target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testMerge() throws Exception { try { config.removeDevice("Test-Device-1", null); } catch (ConfigurationNotFoundException e) {} Device device = createDevice("Test-Device-1", "TEST-AET1"); config.persist(device, null); modifyDevice(device); config.merge(device, null); ApplicationEntity ae2 = config.findApplicationEntity("TEST-AET2"); ApplicationEntity ae = ae2.getDevice().getApplicationEntity("TEST-AET1"); assertTrue(ae.isAssociationInitiator()); assertFalse(ae.isAssociationAcceptor()); assertFalse(ae.getConnections().get(0).isServer()); TransferCapability echoSCP = ae.getTransferCapabilityFor( UID.Verification, TransferCapability.Role.SCP); assertNull(echoSCP); TransferCapability echoSCU = ae.getTransferCapabilityFor( UID.Verification, TransferCapability.Role.SCU); assertNotNull(echoSCU); TransferCapability ctSCP = ae.getTransferCapabilityFor( UID.CTImageStorage, TransferCapability.Role.SCP); assertEquals(STORAGE_OPTIONS, ctSCP.getStorageOptions()); TransferCapability findSCP = ae.getTransferCapabilityFor( UID.StudyRootQueryRetrieveInformationModelFind, TransferCapability.Role.SCP); assertEquals(EnumSet.of(QueryOption.RELATIONAL, QueryOption.DATETIME), findSCP.getQueryOptions()); config.removeDevice("Test-Device-1", null); }
@Override public ConfigurationChanges merge(Device device, EnumSet<Option> options) throws ConfigurationException { ConfigurationChanges diffs = configurationChangesOf(options); merge(device, options, diffs); return diffs; }
LdapDicomConfiguration implements DicomConfiguration { @Override public ConfigurationChanges merge(Device device, EnumSet<Option> options) throws ConfigurationException { ConfigurationChanges diffs = configurationChangesOf(options); merge(device, options, diffs); return diffs; } }
LdapDicomConfiguration implements DicomConfiguration { @Override public ConfigurationChanges merge(Device device, EnumSet<Option> options) throws ConfigurationException { ConfigurationChanges diffs = configurationChangesOf(options); merge(device, options, diffs); return diffs; } LdapDicomConfiguration(); @SuppressWarnings("unchecked") LdapDicomConfiguration(Hashtable<?,?> env); }
LdapDicomConfiguration implements DicomConfiguration { @Override public ConfigurationChanges merge(Device device, EnumSet<Option> options) throws ConfigurationException { ConfigurationChanges diffs = configurationChangesOf(options); merge(device, options, diffs); return diffs; } LdapDicomConfiguration(); @SuppressWarnings("unchecked") LdapDicomConfiguration(Hashtable<?,?> env); final boolean isExtended(); final void setExtended(boolean extended); final void setConfigurationCN(String configurationCN); final String getConfigurationCN(); final void setConfigurationRoot(String configurationRoot); final String getConfigurationRoot(); void setPkiUser(String pkiUser); String getPkiUser(); void setUserCertificate(String userCertificate); String getUserCertificate(); void addDicomConfigurationExtension(LdapDicomConfigurationExtension ext); boolean removeDicomConfigurationExtension( LdapDicomConfigurationExtension ext); @SuppressWarnings("unchecked") @Override T getDicomConfigurationExtension(Class<T> clazz); @Override synchronized void close(); @Override synchronized boolean configurationExists(); boolean exists(String dn); @Override synchronized boolean purgeConfiguration(); @Override synchronized boolean registerAETitle(String aet); @Override synchronized boolean registerWebAppName(String webAppName); @Override synchronized void unregisterAETitle(String aet); @Override synchronized void unregisterWebAppName(String webAppName); @Override synchronized ApplicationEntity findApplicationEntity(String aet); @Override synchronized WebApplication findWebApplication(String name); synchronized Device findDevice(String filter, String childName); Connection findConnection(String connDN, Map<String, Connection> cache); @Override synchronized Device findDevice(String name); @Override synchronized DeviceInfo[] listDeviceInfos(DeviceInfo keys); @Override synchronized String[] listDeviceNames(); @Override synchronized String[] listRegisteredAETitles(); @Override synchronized String[] listRegisteredWebAppNames(); synchronized String[] list(String dn, String filter, String attrID); @Override synchronized ConfigurationChanges persist(Device device, EnumSet<Option> options); @Override ConfigurationChanges merge(Device device, EnumSet<Option> options); @Override synchronized ConfigurationChanges removeDevice(String name, EnumSet<Option> options); synchronized void createSubcontext(String name, Attributes attrs); synchronized void destroySubcontext(String dn); synchronized void destroySubcontextWithChilds(String name); String getConfigurationDN(); void ensureConfigurationExists(); @Override synchronized void persistCertificates(String dn, X509Certificate... certs); @Override synchronized void removeCertificates(String dn); @Override synchronized X509Certificate[] findCertificates(String dn); @Override byte[][] loadDeviceVendorData(String deviceName); @Override ConfigurationChanges updateDeviceVendorData(String deviceName, byte[]... vendorData); Device loadDevice(String deviceDN); Attributes getAttributes(String name); Attributes getAttributes(String name, String[] attrIDs); NamingEnumeration<SearchResult> search(String dn, String filter); NamingEnumeration<SearchResult> search(String dn, String filter, String... attrs); void modifyAttributes(String dn, List<ModificationItem> mods); void replaceAttributes(String dn, Attributes attrs); @Override String deviceRef(String name); void store(ConfigurationChanges diffs, Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void load(Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void merge(ConfigurationChanges diffs, Map<String,BasicBulkDataDescriptor> prevs, Map<String,BasicBulkDataDescriptor> descriptors, String parentDN); void store(AttributeCoercions coercions, String parentDN); void load(AttributeCoercions acs, String dn); void merge(ConfigurationChanges diffs, AttributeCoercions prevs, AttributeCoercions acs, String parentDN); @Override void sync(); @Override synchronized ApplicationEntityInfo[] listAETInfos(ApplicationEntityInfo keys); @Override synchronized WebApplicationInfo[] listWebApplicationInfos(WebApplicationInfo keys); NamingEnumeration<SearchResult> search(String deviceName, String[] attrsArray, String filter); }
LdapDicomConfiguration implements DicomConfiguration { @Override public ConfigurationChanges merge(Device device, EnumSet<Option> options) throws ConfigurationException { ConfigurationChanges diffs = configurationChangesOf(options); merge(device, options, diffs); return diffs; } LdapDicomConfiguration(); @SuppressWarnings("unchecked") LdapDicomConfiguration(Hashtable<?,?> env); final boolean isExtended(); final void setExtended(boolean extended); final void setConfigurationCN(String configurationCN); final String getConfigurationCN(); final void setConfigurationRoot(String configurationRoot); final String getConfigurationRoot(); void setPkiUser(String pkiUser); String getPkiUser(); void setUserCertificate(String userCertificate); String getUserCertificate(); void addDicomConfigurationExtension(LdapDicomConfigurationExtension ext); boolean removeDicomConfigurationExtension( LdapDicomConfigurationExtension ext); @SuppressWarnings("unchecked") @Override T getDicomConfigurationExtension(Class<T> clazz); @Override synchronized void close(); @Override synchronized boolean configurationExists(); boolean exists(String dn); @Override synchronized boolean purgeConfiguration(); @Override synchronized boolean registerAETitle(String aet); @Override synchronized boolean registerWebAppName(String webAppName); @Override synchronized void unregisterAETitle(String aet); @Override synchronized void unregisterWebAppName(String webAppName); @Override synchronized ApplicationEntity findApplicationEntity(String aet); @Override synchronized WebApplication findWebApplication(String name); synchronized Device findDevice(String filter, String childName); Connection findConnection(String connDN, Map<String, Connection> cache); @Override synchronized Device findDevice(String name); @Override synchronized DeviceInfo[] listDeviceInfos(DeviceInfo keys); @Override synchronized String[] listDeviceNames(); @Override synchronized String[] listRegisteredAETitles(); @Override synchronized String[] listRegisteredWebAppNames(); synchronized String[] list(String dn, String filter, String attrID); @Override synchronized ConfigurationChanges persist(Device device, EnumSet<Option> options); @Override ConfigurationChanges merge(Device device, EnumSet<Option> options); @Override synchronized ConfigurationChanges removeDevice(String name, EnumSet<Option> options); synchronized void createSubcontext(String name, Attributes attrs); synchronized void destroySubcontext(String dn); synchronized void destroySubcontextWithChilds(String name); String getConfigurationDN(); void ensureConfigurationExists(); @Override synchronized void persistCertificates(String dn, X509Certificate... certs); @Override synchronized void removeCertificates(String dn); @Override synchronized X509Certificate[] findCertificates(String dn); @Override byte[][] loadDeviceVendorData(String deviceName); @Override ConfigurationChanges updateDeviceVendorData(String deviceName, byte[]... vendorData); Device loadDevice(String deviceDN); Attributes getAttributes(String name); Attributes getAttributes(String name, String[] attrIDs); NamingEnumeration<SearchResult> search(String dn, String filter); NamingEnumeration<SearchResult> search(String dn, String filter, String... attrs); void modifyAttributes(String dn, List<ModificationItem> mods); void replaceAttributes(String dn, Attributes attrs); @Override String deviceRef(String name); void store(ConfigurationChanges diffs, Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void load(Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void merge(ConfigurationChanges diffs, Map<String,BasicBulkDataDescriptor> prevs, Map<String,BasicBulkDataDescriptor> descriptors, String parentDN); void store(AttributeCoercions coercions, String parentDN); void load(AttributeCoercions acs, String dn); void merge(ConfigurationChanges diffs, AttributeCoercions prevs, AttributeCoercions acs, String parentDN); @Override void sync(); @Override synchronized ApplicationEntityInfo[] listAETInfos(ApplicationEntityInfo keys); @Override synchronized WebApplicationInfo[] listWebApplicationInfos(WebApplicationInfo keys); NamingEnumeration<SearchResult> search(String deviceName, String[] attrsArray, String filter); }
@Test public void testParseTMacrnema() { DatePrecision precision = new DatePrecision(); assertEquals(0, DateUtils.parseTM(tz, "02:00:00", precision).getTime()); assertEquals(Calendar.SECOND, precision.lastField); }
public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); static final Date[] EMPTY_DATES; }
@Test public void testParseTMceil() { DatePrecision precision = new DatePrecision(); assertEquals(MINUTE - 1, DateUtils.parseTM(tz, "0200", true, precision).getTime()); assertEquals(Calendar.MINUTE, precision.lastField); }
public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); }
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); static final Date[] EMPTY_DATES; }
@Test public void testParseDT() { DatePrecision precision = new DatePrecision(); assertEquals(0, DateUtils.parseDT(tz, "19700101020000.000", precision).getTime()); assertEquals(Calendar.MILLISECOND, precision.lastField); assertFalse(precision.includeTimezone); }
public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); static final Date[] EMPTY_DATES; }
@Test public void testParseWithTZ() { DatePrecision precision = new DatePrecision(); assertEquals(2 * HOUR, DateUtils.parseDT(tz, "19700101020000.000+0000", precision).getTime()); assertEquals(Calendar.MILLISECOND, precision.lastField); assertTrue(precision.includeTimezone); }
public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); static final Date[] EMPTY_DATES; }
@Test public void testParseDTceil() { DatePrecision precision = new DatePrecision(); assertEquals(YEAR - 2 * HOUR - 1, DateUtils.parseDT(tz, "1970", true, precision).getTime()); assertEquals(Calendar.YEAR, precision.lastField); assertFalse(precision.includeTimezone); }
public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); }
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date, StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date, StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil, DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil, DatePrecision precision); static final Date[] EMPTY_DATES; }
@Test public void testSize() { assertEquals(15, map.size()); removeOdd(); assertEquals(7, map.size()); }
public int size() { return size; }
IntHashMap implements Cloneable, java.io.Serializable { public int size() { return size; } }
IntHashMap implements Cloneable, java.io.Serializable { public int size() { return size; } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { public int size() { return size; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { public int size() { return size; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testGet() { removeOdd(); testGet(map); }
@SuppressWarnings("unchecked") public V get(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return (V) values[i]; i = (i + 1) & mask; } return null; }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V get(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return (V) values[i]; i = (i + 1) & mask; } return null; } }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V get(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return (V) values[i]; i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V get(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return (V) values[i]; i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V get(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return (V) values[i]; i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testPut() { removeOdd(); for (int i = 0; i < 45; i++) map.put(i, Integer.valueOf(i)); assertEquals(45, map.size()); for (int i = 0; i < 45; i++) assertEquals(Integer.valueOf(i), map.get(i)); }
@SuppressWarnings("unchecked") public V put(int key, V value) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] > FREE) { if (keys[i] == key) { V oldValue = (V) values[i]; values[i] = value; return oldValue; } i = (i + 1) & mask; } byte oldState = states[i]; states[i] = FULL; keys[i] = key; values[i] = value; ++size; if (oldState == FREE && --free < 0) resize(Math.max(capacity(size), keys.length)); return null; }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V put(int key, V value) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] > FREE) { if (keys[i] == key) { V oldValue = (V) values[i]; values[i] = value; return oldValue; } i = (i + 1) & mask; } byte oldState = states[i]; states[i] = FULL; keys[i] = key; values[i] = value; ++size; if (oldState == FREE && --free < 0) resize(Math.max(capacity(size), keys.length)); return null; } }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V put(int key, V value) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] > FREE) { if (keys[i] == key) { V oldValue = (V) values[i]; values[i] = value; return oldValue; } i = (i + 1) & mask; } byte oldState = states[i]; states[i] = FULL; keys[i] = key; values[i] = value; ++size; if (oldState == FREE && --free < 0) resize(Math.max(capacity(size), keys.length)); return null; } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V put(int key, V value) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] > FREE) { if (keys[i] == key) { V oldValue = (V) values[i]; values[i] = value; return oldValue; } i = (i + 1) & mask; } byte oldState = states[i]; states[i] = FULL; keys[i] = key; values[i] = value; ++size; if (oldState == FREE && --free < 0) resize(Math.max(capacity(size), keys.length)); return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V put(int key, V value) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] > FREE) { if (keys[i] == key) { V oldValue = (V) values[i]; values[i] = value; return oldValue; } i = (i + 1) & mask; } byte oldState = states[i]; states[i] = FULL; keys[i] = key; values[i] = value; ++size; if (oldState == FREE && --free < 0) resize(Math.max(capacity(size), keys.length)); return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testContainsKey() { removeOdd(); for (int i = 1; i < 45; i++) assertEquals((i & 1) == 0 && (i % 3) == 1, map.containsKey(i)); }
public boolean containsKey(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return states[i] > FREE; i = (i + 1) & mask; } return false; }
IntHashMap implements Cloneable, java.io.Serializable { public boolean containsKey(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return states[i] > FREE; i = (i + 1) & mask; } return false; } }
IntHashMap implements Cloneable, java.io.Serializable { public boolean containsKey(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return states[i] > FREE; i = (i + 1) & mask; } return false; } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { public boolean containsKey(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return states[i] > FREE; i = (i + 1) & mask; } return false; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { public boolean containsKey(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return states[i] > FREE; i = (i + 1) & mask; } return false; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testRehash() { removeOdd(); map.trimToSize(); testGet(map); }
public void rehash() { resize(keys.length); }
IntHashMap implements Cloneable, java.io.Serializable { public void rehash() { resize(keys.length); } }
IntHashMap implements Cloneable, java.io.Serializable { public void rehash() { resize(keys.length); } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { public void rehash() { resize(keys.length); } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { public void rehash() { resize(keys.length); } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testWriteTo() throws Exception { StringWriter writer = new StringWriter(); try ( JsonGenerator gen = Json.createGenerator(writer)) { JsonConfiguration config = new JsonConfiguration(); config.addJsonConfigurationExtension(new JsonAuditLoggerConfiguration()); config.addJsonConfigurationExtension(new JsonAuditRecordRepositoryConfiguration()); config.addJsonConfigurationExtension(new JsonImageReaderConfiguration()); config.addJsonConfigurationExtension(new JsonImageWriterConfiguration()); config.addJsonConfigurationExtension(new JsonHL7Configuration()); config.writeTo(createDevice("Test-Device-1", "TEST-AET1"), gen, true); } Path path = Paths.get("src/test/data/device.json"); try (BufferedReader reader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { assertEquals(reader.readLine(), writer.toString()); } }
public void writeTo(DeviceInfo deviceInfo, JsonGenerator gen) { JsonWriter writer = new JsonWriter(gen); gen.writeStartObject(); gen.write("dicomDeviceName", deviceInfo.getDeviceName()); writer.writeNotNullOrDef("dicomDescription", deviceInfo.getDescription(), null); writer.writeNotNullOrDef("dicomManufacturer", deviceInfo.getManufacturer(), null); writer.writeNotNullOrDef("dicomManufacturerModelName", deviceInfo.getManufacturerModelName(), null); writer.writeNotEmpty("dicomSoftwareVersion", deviceInfo.getSoftwareVersions()); writer.writeNotNullOrDef("dicomStationName", deviceInfo.getStationName(), null); writer.writeNotEmpty("dicomInstitutionName", deviceInfo.getInstitutionNames()); writer.writeNotEmpty("dicomInstitutionDepartmentName", deviceInfo.getInstitutionalDepartmentNames()); writer.writeNotEmpty("dicomPrimaryDeviceType", deviceInfo.getPrimaryDeviceTypes()); gen.write("dicomInstalled", deviceInfo.getInstalled()); gen.write("hasArcDevExt", deviceInfo.getArcDevExt()); gen.writeEnd(); }
JsonConfiguration { public void writeTo(DeviceInfo deviceInfo, JsonGenerator gen) { JsonWriter writer = new JsonWriter(gen); gen.writeStartObject(); gen.write("dicomDeviceName", deviceInfo.getDeviceName()); writer.writeNotNullOrDef("dicomDescription", deviceInfo.getDescription(), null); writer.writeNotNullOrDef("dicomManufacturer", deviceInfo.getManufacturer(), null); writer.writeNotNullOrDef("dicomManufacturerModelName", deviceInfo.getManufacturerModelName(), null); writer.writeNotEmpty("dicomSoftwareVersion", deviceInfo.getSoftwareVersions()); writer.writeNotNullOrDef("dicomStationName", deviceInfo.getStationName(), null); writer.writeNotEmpty("dicomInstitutionName", deviceInfo.getInstitutionNames()); writer.writeNotEmpty("dicomInstitutionDepartmentName", deviceInfo.getInstitutionalDepartmentNames()); writer.writeNotEmpty("dicomPrimaryDeviceType", deviceInfo.getPrimaryDeviceTypes()); gen.write("dicomInstalled", deviceInfo.getInstalled()); gen.write("hasArcDevExt", deviceInfo.getArcDevExt()); gen.writeEnd(); } }
JsonConfiguration { public void writeTo(DeviceInfo deviceInfo, JsonGenerator gen) { JsonWriter writer = new JsonWriter(gen); gen.writeStartObject(); gen.write("dicomDeviceName", deviceInfo.getDeviceName()); writer.writeNotNullOrDef("dicomDescription", deviceInfo.getDescription(), null); writer.writeNotNullOrDef("dicomManufacturer", deviceInfo.getManufacturer(), null); writer.writeNotNullOrDef("dicomManufacturerModelName", deviceInfo.getManufacturerModelName(), null); writer.writeNotEmpty("dicomSoftwareVersion", deviceInfo.getSoftwareVersions()); writer.writeNotNullOrDef("dicomStationName", deviceInfo.getStationName(), null); writer.writeNotEmpty("dicomInstitutionName", deviceInfo.getInstitutionNames()); writer.writeNotEmpty("dicomInstitutionDepartmentName", deviceInfo.getInstitutionalDepartmentNames()); writer.writeNotEmpty("dicomPrimaryDeviceType", deviceInfo.getPrimaryDeviceTypes()); gen.write("dicomInstalled", deviceInfo.getInstalled()); gen.write("hasArcDevExt", deviceInfo.getArcDevExt()); gen.writeEnd(); } }
JsonConfiguration { public void writeTo(DeviceInfo deviceInfo, JsonGenerator gen) { JsonWriter writer = new JsonWriter(gen); gen.writeStartObject(); gen.write("dicomDeviceName", deviceInfo.getDeviceName()); writer.writeNotNullOrDef("dicomDescription", deviceInfo.getDescription(), null); writer.writeNotNullOrDef("dicomManufacturer", deviceInfo.getManufacturer(), null); writer.writeNotNullOrDef("dicomManufacturerModelName", deviceInfo.getManufacturerModelName(), null); writer.writeNotEmpty("dicomSoftwareVersion", deviceInfo.getSoftwareVersions()); writer.writeNotNullOrDef("dicomStationName", deviceInfo.getStationName(), null); writer.writeNotEmpty("dicomInstitutionName", deviceInfo.getInstitutionNames()); writer.writeNotEmpty("dicomInstitutionDepartmentName", deviceInfo.getInstitutionalDepartmentNames()); writer.writeNotEmpty("dicomPrimaryDeviceType", deviceInfo.getPrimaryDeviceTypes()); gen.write("dicomInstalled", deviceInfo.getInstalled()); gen.write("hasArcDevExt", deviceInfo.getArcDevExt()); gen.writeEnd(); } void addJsonConfigurationExtension(JsonConfigurationExtension ext); boolean removeJsonConfigurationExtension(JsonConfigurationExtension ext); T getJsonConfigurationExtension(Class<T> clazz); void writeTo(DeviceInfo deviceInfo, JsonGenerator gen); void writeTo(ApplicationEntityInfo aetInfo, JsonGenerator gen); void writeTo(WebApplicationInfo webappInfo, JsonGenerator gen); void writeTo(WebApplicationInfo webappInfo, JsonGenerator gen, String keycloakClientID); void writeTo(HL7ApplicationInfo hl7AppInfo, JsonGenerator gen); void writeTo(Device device, JsonGenerator gen, boolean extended); Device loadDeviceFrom(JsonParser parser, ConfigurationDelegate config); void writeBulkdataDescriptors(Map<String, BasicBulkDataDescriptor> descriptors, JsonWriter writer); void loadBulkdataDescriptors(Map<String, BasicBulkDataDescriptor> descriptors, JsonReader reader); }
JsonConfiguration { public void writeTo(DeviceInfo deviceInfo, JsonGenerator gen) { JsonWriter writer = new JsonWriter(gen); gen.writeStartObject(); gen.write("dicomDeviceName", deviceInfo.getDeviceName()); writer.writeNotNullOrDef("dicomDescription", deviceInfo.getDescription(), null); writer.writeNotNullOrDef("dicomManufacturer", deviceInfo.getManufacturer(), null); writer.writeNotNullOrDef("dicomManufacturerModelName", deviceInfo.getManufacturerModelName(), null); writer.writeNotEmpty("dicomSoftwareVersion", deviceInfo.getSoftwareVersions()); writer.writeNotNullOrDef("dicomStationName", deviceInfo.getStationName(), null); writer.writeNotEmpty("dicomInstitutionName", deviceInfo.getInstitutionNames()); writer.writeNotEmpty("dicomInstitutionDepartmentName", deviceInfo.getInstitutionalDepartmentNames()); writer.writeNotEmpty("dicomPrimaryDeviceType", deviceInfo.getPrimaryDeviceTypes()); gen.write("dicomInstalled", deviceInfo.getInstalled()); gen.write("hasArcDevExt", deviceInfo.getArcDevExt()); gen.writeEnd(); } void addJsonConfigurationExtension(JsonConfigurationExtension ext); boolean removeJsonConfigurationExtension(JsonConfigurationExtension ext); T getJsonConfigurationExtension(Class<T> clazz); void writeTo(DeviceInfo deviceInfo, JsonGenerator gen); void writeTo(ApplicationEntityInfo aetInfo, JsonGenerator gen); void writeTo(WebApplicationInfo webappInfo, JsonGenerator gen); void writeTo(WebApplicationInfo webappInfo, JsonGenerator gen, String keycloakClientID); void writeTo(HL7ApplicationInfo hl7AppInfo, JsonGenerator gen); void writeTo(Device device, JsonGenerator gen, boolean extended); Device loadDeviceFrom(JsonParser parser, ConfigurationDelegate config); void writeBulkdataDescriptors(Map<String, BasicBulkDataDescriptor> descriptors, JsonWriter writer); void loadBulkdataDescriptors(Map<String, BasicBulkDataDescriptor> descriptors, JsonReader reader); }
@Test public void testRemove() { for (int i = 1; i < 45; i += 2) if ((i % 3) == 1) assertEquals(Integer.valueOf(i), map.remove(i)); else assertNull(map.remove(i)); }
@SuppressWarnings("unchecked") public V remove(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) { if (states[i] < FREE) return null; states[i] = REMOVED; V oldValue = (V) values[i]; values[i] = null; size--; return oldValue; } i = (i + 1) & mask; } return null; }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V remove(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) { if (states[i] < FREE) return null; states[i] = REMOVED; V oldValue = (V) values[i]; values[i] = null; size--; return oldValue; } i = (i + 1) & mask; } return null; } }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V remove(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) { if (states[i] < FREE) return null; states[i] = REMOVED; V oldValue = (V) values[i]; values[i] = null; size--; return oldValue; } i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V remove(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) { if (states[i] < FREE) return null; states[i] = REMOVED; V oldValue = (V) values[i]; values[i] = null; size--; return oldValue; } i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V remove(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) { if (states[i] < FREE) return null; states[i] = REMOVED; V oldValue = (V) values[i]; values[i] = null; size--; return oldValue; } i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testClear() { assertFalse(map.isEmpty()); map.clear(); assertTrue(map.isEmpty()); }
public void clear() { Arrays.fill(values, null); Arrays.fill(states, FREE); size = 0; free = keys.length >>> 1; }
IntHashMap implements Cloneable, java.io.Serializable { public void clear() { Arrays.fill(values, null); Arrays.fill(states, FREE); size = 0; free = keys.length >>> 1; } }
IntHashMap implements Cloneable, java.io.Serializable { public void clear() { Arrays.fill(values, null); Arrays.fill(states, FREE); size = 0; free = keys.length >>> 1; } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { public void clear() { Arrays.fill(values, null); Arrays.fill(states, FREE); size = 0; free = keys.length >>> 1; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { public void clear() { Arrays.fill(values, null); Arrays.fill(states, FREE); size = 0; free = keys.length >>> 1; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@SuppressWarnings("unchecked") @Test public void testClone() { removeOdd(); IntHashMap<Integer> clone = (IntHashMap<Integer>) map.clone(); map.clear(); testGet(clone); }
@SuppressWarnings("unchecked") public Object clone() { try { IntHashMap<V> m = (IntHashMap<V>) super.clone(); m.states = states.clone(); m.keys = keys.clone(); m.values = values.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(); } }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public Object clone() { try { IntHashMap<V> m = (IntHashMap<V>) super.clone(); m.states = states.clone(); m.keys = keys.clone(); m.values = values.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(); } } }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public Object clone() { try { IntHashMap<V> m = (IntHashMap<V>) super.clone(); m.states = states.clone(); m.keys = keys.clone(); m.values = values.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(); } } IntHashMap(); IntHashMap(int expectedMaxSize); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public Object clone() { try { IntHashMap<V> m = (IntHashMap<V>) super.clone(); m.states = states.clone(); m.keys = keys.clone(); m.values = values.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(); } } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public Object clone() { try { IntHashMap<V> m = (IntHashMap<V>) super.clone(); m.states = states.clone(); m.keys = keys.clone(); m.values = values.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(); } } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); }
@Test public void testBytesToUShortBE() { assertEquals(-12345 & 0xffff, ByteUtils.bytesToUShortBE(SHORT_12345_BE, 0)); }
public static int bytesToUShortBE(byte[] bytes, int off) { return ((bytes[off] & 255) << 8) + (bytes[off + 1] & 255); }
ByteUtils { public static int bytesToUShortBE(byte[] bytes, int off) { return ((bytes[off] & 255) << 8) + (bytes[off + 1] & 255); } }
ByteUtils { public static int bytesToUShortBE(byte[] bytes, int off) { return ((bytes[off] & 255) << 8) + (bytes[off + 1] & 255); } }
ByteUtils { public static int bytesToUShortBE(byte[] bytes, int off) { return ((bytes[off] & 255) << 8) + (bytes[off + 1] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToUShortBE(byte[] bytes, int off) { return ((bytes[off] & 255) << 8) + (bytes[off + 1] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToUShortLE() { assertEquals(-12345 & 0xffff, ByteUtils.bytesToUShortLE(SHORT_12345_LE, 0)); }
public static int bytesToUShortLE(byte[] bytes, int off) { return ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); }
ByteUtils { public static int bytesToUShortLE(byte[] bytes, int off) { return ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } }
ByteUtils { public static int bytesToUShortLE(byte[] bytes, int off) { return ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } }
ByteUtils { public static int bytesToUShortLE(byte[] bytes, int off) { return ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToUShortLE(byte[] bytes, int off) { return ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToShortBE() { assertEquals(-12345, ByteUtils.bytesToShortBE(SHORT_12345_BE, 0)); }
public static int bytesToShortBE(byte[] bytes, int off) { return (bytes[off] << 8) + (bytes[off + 1] & 255); }
ByteUtils { public static int bytesToShortBE(byte[] bytes, int off) { return (bytes[off] << 8) + (bytes[off + 1] & 255); } }
ByteUtils { public static int bytesToShortBE(byte[] bytes, int off) { return (bytes[off] << 8) + (bytes[off + 1] & 255); } }
ByteUtils { public static int bytesToShortBE(byte[] bytes, int off) { return (bytes[off] << 8) + (bytes[off + 1] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToShortBE(byte[] bytes, int off) { return (bytes[off] << 8) + (bytes[off + 1] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToShortLE() { assertEquals(-12345, ByteUtils.bytesToShortLE(SHORT_12345_LE, 0)); }
public static int bytesToShortLE(byte[] bytes, int off) { return (bytes[off + 1] << 8) + (bytes[off] & 255); }
ByteUtils { public static int bytesToShortLE(byte[] bytes, int off) { return (bytes[off + 1] << 8) + (bytes[off] & 255); } }
ByteUtils { public static int bytesToShortLE(byte[] bytes, int off) { return (bytes[off + 1] << 8) + (bytes[off] & 255); } }
ByteUtils { public static int bytesToShortLE(byte[] bytes, int off) { return (bytes[off + 1] << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToShortLE(byte[] bytes, int off) { return (bytes[off + 1] << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToIntBE() { assertEquals(-12345, ByteUtils.bytesToIntBE(INT_12345_BE, 0)); }
public static int bytesToIntBE(byte[] bytes, int off) { return (bytes[off] << 24) + ((bytes[off + 1] & 255) << 16) + ((bytes[off + 2] & 255) << 8) + (bytes[off + 3] & 255); }
ByteUtils { public static int bytesToIntBE(byte[] bytes, int off) { return (bytes[off] << 24) + ((bytes[off + 1] & 255) << 16) + ((bytes[off + 2] & 255) << 8) + (bytes[off + 3] & 255); } }
ByteUtils { public static int bytesToIntBE(byte[] bytes, int off) { return (bytes[off] << 24) + ((bytes[off + 1] & 255) << 16) + ((bytes[off + 2] & 255) << 8) + (bytes[off + 3] & 255); } }
ByteUtils { public static int bytesToIntBE(byte[] bytes, int off) { return (bytes[off] << 24) + ((bytes[off + 1] & 255) << 16) + ((bytes[off + 2] & 255) << 8) + (bytes[off + 3] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToIntBE(byte[] bytes, int off) { return (bytes[off] << 24) + ((bytes[off + 1] & 255) << 16) + ((bytes[off + 2] & 255) << 8) + (bytes[off + 3] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToIntLE() { assertEquals(-12345, ByteUtils.bytesToIntLE(INT_12345_LE, 0)); }
public static int bytesToIntLE(byte[] bytes, int off) { return (bytes[off + 3] << 24) + ((bytes[off + 2] & 255) << 16) + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); }
ByteUtils { public static int bytesToIntLE(byte[] bytes, int off) { return (bytes[off + 3] << 24) + ((bytes[off + 2] & 255) << 16) + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } }
ByteUtils { public static int bytesToIntLE(byte[] bytes, int off) { return (bytes[off + 3] << 24) + ((bytes[off + 2] & 255) << 16) + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } }
ByteUtils { public static int bytesToIntLE(byte[] bytes, int off) { return (bytes[off + 3] << 24) + ((bytes[off + 2] & 255) << 16) + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToIntLE(byte[] bytes, int off) { return (bytes[off + 3] << 24) + ((bytes[off + 2] & 255) << 16) + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToTagBE() { assertEquals(Tag.PixelData, ByteUtils.bytesToTagBE(TAG_PIXEL_DATA_BE, 0)); }
public static int bytesToTagBE(byte[] bytes, int off) { return bytesToIntBE(bytes, off); }
ByteUtils { public static int bytesToTagBE(byte[] bytes, int off) { return bytesToIntBE(bytes, off); } }
ByteUtils { public static int bytesToTagBE(byte[] bytes, int off) { return bytesToIntBE(bytes, off); } }
ByteUtils { public static int bytesToTagBE(byte[] bytes, int off) { return bytesToIntBE(bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToTagBE(byte[] bytes, int off) { return bytesToIntBE(bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testToString() { ItemPointer ip = new ItemPointer(Tag.RequestAttributesSequence); AttributeSelector selector = new AttributeSelector(Tag.StudyInstanceUID, null, ip); assertEquals(XPATH, selector.toString()); }
@Override public String toString() { if (str == null) str = toStringBuilder().toString(); return str; }
AttributeSelector implements Serializable { @Override public String toString() { if (str == null) str = toStringBuilder().toString(); return str; } }
AttributeSelector implements Serializable { @Override public String toString() { if (str == null) str = toStringBuilder().toString(); return str; } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); }
AttributeSelector implements Serializable { @Override public String toString() { if (str == null) str = toStringBuilder().toString(); return str; } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); }
AttributeSelector implements Serializable { @Override public String toString() { if (str == null) str = toStringBuilder().toString(); return str; } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); }
@Test public void testBytesToTagLE() { assertEquals(Tag.PixelData, ByteUtils.bytesToTagLE(TAG_PIXEL_DATA_LE, 0)); }
public static int bytesToTagLE(byte[] bytes, int off) { return (bytes[off + 1] << 24) + ((bytes[off] & 255) << 16) + ((bytes[off + 3] & 255) << 8) + (bytes[off + 2] & 255); }
ByteUtils { public static int bytesToTagLE(byte[] bytes, int off) { return (bytes[off + 1] << 24) + ((bytes[off] & 255) << 16) + ((bytes[off + 3] & 255) << 8) + (bytes[off + 2] & 255); } }
ByteUtils { public static int bytesToTagLE(byte[] bytes, int off) { return (bytes[off + 1] << 24) + ((bytes[off] & 255) << 16) + ((bytes[off + 3] & 255) << 8) + (bytes[off + 2] & 255); } }
ByteUtils { public static int bytesToTagLE(byte[] bytes, int off) { return (bytes[off + 1] << 24) + ((bytes[off] & 255) << 16) + ((bytes[off + 3] & 255) << 8) + (bytes[off + 2] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static int bytesToTagLE(byte[] bytes, int off) { return (bytes[off + 1] << 24) + ((bytes[off] & 255) << 16) + ((bytes[off + 3] & 255) << 8) + (bytes[off + 2] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToFloatBE() { assertEquals((float) Math.PI, ByteUtils.bytesToFloatBE(FLOAT_PI_BE, 0), 0); }
public static float bytesToFloatBE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntBE(bytes, off)); }
ByteUtils { public static float bytesToFloatBE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntBE(bytes, off)); } }
ByteUtils { public static float bytesToFloatBE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntBE(bytes, off)); } }
ByteUtils { public static float bytesToFloatBE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntBE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static float bytesToFloatBE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntBE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToFloatLE() { assertEquals((float) Math.PI, ByteUtils.bytesToFloatLE(FLOAT_PI_LE, 0), 0); }
public static float bytesToFloatLE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntLE(bytes, off)); }
ByteUtils { public static float bytesToFloatLE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntLE(bytes, off)); } }
ByteUtils { public static float bytesToFloatLE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntLE(bytes, off)); } }
ByteUtils { public static float bytesToFloatLE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntLE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static float bytesToFloatLE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntLE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToDoubleBE() { assertEquals(Math.PI, ByteUtils.bytesToDoubleBE(DOUBLE_PI_BE, 0), 0); }
public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); }
ByteUtils { public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); } }
ByteUtils { public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); } }
ByteUtils { public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testBytesToDoubleLE() { assertEquals(Math.PI, ByteUtils.bytesToDoubleLE(DOUBLE_PI_LE, 0), 0); }
public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); }
ByteUtils { public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); } }
ByteUtils { public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); } }
ByteUtils { public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testShortToBytesBE() { assertArrayEquals(SHORT_12345_BE, ByteUtils.shortToBytesBE(-12345, new byte[2] , 0)); }
public static byte[] shortToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 8); bytes[off + 1] = (byte) i; return bytes; }
ByteUtils { public static byte[] shortToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 8); bytes[off + 1] = (byte) i; return bytes; } }
ByteUtils { public static byte[] shortToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 8); bytes[off + 1] = (byte) i; return bytes; } }
ByteUtils { public static byte[] shortToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 8); bytes[off + 1] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static byte[] shortToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 8); bytes[off + 1] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testShortToBytesLE() { assertArrayEquals(SHORT_12345_LE, ByteUtils.shortToBytesLE(-12345, new byte[2] , 0)); }
public static byte[] shortToBytesLE(int i, byte[] bytes, int off) { bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; }
ByteUtils { public static byte[] shortToBytesLE(int i, byte[] bytes, int off) { bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } }
ByteUtils { public static byte[] shortToBytesLE(int i, byte[] bytes, int off) { bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } }
ByteUtils { public static byte[] shortToBytesLE(int i, byte[] bytes, int off) { bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static byte[] shortToBytesLE(int i, byte[] bytes, int off) { bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testIntToBytesBE() { assertArrayEquals(INT_12345_BE, ByteUtils.intToBytesBE(-12345, new byte[4] , 0)); }
public static byte[] intToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 24); bytes[off + 1] = (byte) (i >> 16); bytes[off + 2] = (byte) (i >> 8); bytes[off + 3] = (byte) i; return bytes; }
ByteUtils { public static byte[] intToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 24); bytes[off + 1] = (byte) (i >> 16); bytes[off + 2] = (byte) (i >> 8); bytes[off + 3] = (byte) i; return bytes; } }
ByteUtils { public static byte[] intToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 24); bytes[off + 1] = (byte) (i >> 16); bytes[off + 2] = (byte) (i >> 8); bytes[off + 3] = (byte) i; return bytes; } }
ByteUtils { public static byte[] intToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 24); bytes[off + 1] = (byte) (i >> 16); bytes[off + 2] = (byte) (i >> 8); bytes[off + 3] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static byte[] intToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 24); bytes[off + 1] = (byte) (i >> 16); bytes[off + 2] = (byte) (i >> 8); bytes[off + 3] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testIntToBytesLE() { assertArrayEquals(INT_12345_LE, ByteUtils.intToBytesLE(-12345, new byte[4] , 0)); }
public static byte[] intToBytesLE(int i, byte[] bytes, int off) { bytes[off + 3] = (byte) (i >> 24); bytes[off + 2] = (byte) (i >> 16); bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; }
ByteUtils { public static byte[] intToBytesLE(int i, byte[] bytes, int off) { bytes[off + 3] = (byte) (i >> 24); bytes[off + 2] = (byte) (i >> 16); bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } }
ByteUtils { public static byte[] intToBytesLE(int i, byte[] bytes, int off) { bytes[off + 3] = (byte) (i >> 24); bytes[off + 2] = (byte) (i >> 16); bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } }
ByteUtils { public static byte[] intToBytesLE(int i, byte[] bytes, int off) { bytes[off + 3] = (byte) (i >> 24); bytes[off + 2] = (byte) (i >> 16); bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static byte[] intToBytesLE(int i, byte[] bytes, int off) { bytes[off + 3] = (byte) (i >> 24); bytes[off + 2] = (byte) (i >> 16); bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testTagToBytesBE() { assertArrayEquals(TAG_PIXEL_DATA_BE, ByteUtils.tagToBytesBE(Tag.PixelData, new byte[4] , 0)); }
public static byte[] tagToBytesBE(int i, byte[] bytes, int off) { return intToBytesBE(i, bytes, off); }
ByteUtils { public static byte[] tagToBytesBE(int i, byte[] bytes, int off) { return intToBytesBE(i, bytes, off); } }
ByteUtils { public static byte[] tagToBytesBE(int i, byte[] bytes, int off) { return intToBytesBE(i, bytes, off); } }
ByteUtils { public static byte[] tagToBytesBE(int i, byte[] bytes, int off) { return intToBytesBE(i, bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); }
ByteUtils { public static byte[] tagToBytesBE(int i, byte[] bytes, int off) { return intToBytesBE(i, bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off, boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off, boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off, boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off, boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; }
@Test public void testValueOf() { AttributeSelector selector = AttributeSelector.valueOf(XPATH); assertEquals(Tag.StudyInstanceUID, selector.tag()); assertNull(selector.privateCreator()); assertEquals(1, selector.level()); ItemPointer ip = selector.itemPointer(0); assertEquals(Tag.RequestAttributesSequence, ip.sequenceTag); assertNull(ip.privateCreator); assertEquals(-1, ip.itemIndex); }
public static AttributeSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new AttributeSelector( selectTag(s, fromIndex), selectPrivateCreator(s, fromIndex), itemPointersOf(s, fromIndex)); } catch (Exception e) { throw new IllegalArgumentException(s); } }
AttributeSelector implements Serializable { public static AttributeSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new AttributeSelector( selectTag(s, fromIndex), selectPrivateCreator(s, fromIndex), itemPointersOf(s, fromIndex)); } catch (Exception e) { throw new IllegalArgumentException(s); } } }
AttributeSelector implements Serializable { public static AttributeSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new AttributeSelector( selectTag(s, fromIndex), selectPrivateCreator(s, fromIndex), itemPointersOf(s, fromIndex)); } catch (Exception e) { throw new IllegalArgumentException(s); } } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); }
AttributeSelector implements Serializable { public static AttributeSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new AttributeSelector( selectTag(s, fromIndex), selectPrivateCreator(s, fromIndex), itemPointersOf(s, fromIndex)); } catch (Exception e) { throw new IllegalArgumentException(s); } } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); }
AttributeSelector implements Serializable { public static AttributeSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new AttributeSelector( selectTag(s, fromIndex), selectPrivateCreator(s, fromIndex), itemPointersOf(s, fromIndex)); } catch (Exception e) { throw new IllegalArgumentException(s); } } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); }
@Test public void testUndertowHttp2Enabled() { props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue(); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testStartUpProdServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext, never()).addServlet(eq("H2Console"), any(WebServlet.class)); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testStartUpDevServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext).addServlet(eq("H2Console"), any(WebServlet.class)); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testUndertowHttp2Enabled() { props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue(); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
@Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
@Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCorsFilterDeactivated() throws Exception { props.getCors().setAllowedOrigins(null); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
@Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCorsFilterDeactivated2() throws Exception { props.getCors().setAllowedOrigins(new ArrayList<>()); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
@Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); if (container.getDocumentRoot() != null) { assertThat(container.getDocumentRoot().getPath()).isEqualTo("target/www"); } Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testStartUpProdServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext).addFilter(eq("cachingHttpHeadersFilter"), any(CachingHttpHeadersFilter.class)); verify(servletContext, never()).addServlet(eq("H2Console"), any(WebServlet.class)); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testStartUpDevServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext, never()).addFilter(eq("cachingHttpHeadersFilter"), any(CachingHttpHeadersFilter.class)); verify(servletContext).addServlet(eq("H2Console"), any(WebServlet.class)); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); if (container.getDocumentRoot() != null) { assertThat(container.getDocumentRoot().getPath()).isEqualTo("target/www"); } Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); setLocationForStaticAssets(container); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); }
@Test public void testSlug() { System.out.println("getSlug"); Post instance = new Post(); instance.setTitle("test post 1"); instance.slugify(); assertEquals("test-post-1", instance.getSlug()); }
@PrePersist public void slugify(){ this.slug = new Slugify().slugify(this.title); }
Post extends AuditableEntity { @PrePersist public void slugify(){ this.slug = new Slugify().slugify(this.title); } }
Post extends AuditableEntity { @PrePersist public void slugify(){ this.slug = new Slugify().slugify(this.title); } }
Post extends AuditableEntity { @PrePersist public void slugify(){ this.slug = new Slugify().slugify(this.title); } @PrePersist void slugify(); }
Post extends AuditableEntity { @PrePersist public void slugify(){ this.slug = new Slugify().slugify(this.title); } @PrePersist void slugify(); }
@Test public void createPost() { final String TITLE = "test post title"; final String CONTENT = "test post content"; final PostForm input = PostForm.builder().title(TITLE).content(CONTENT).build(); Post expected = Post.builder().title(TITLE).content(CONTENT).build(); expected.setId(1L); given(posts.save(Post.builder().title(input.getTitle()).content(input.getContent()).build())) .willReturn(expected); Post returned = postService.createPost(input); assertTrue(returned == expected); verify(posts, times(1)).save(any(Post.class)); verifyNoMoreInteractions(posts); }
public Post createPost(PostForm form) { Post _post = Post.builder() .title(form.getTitle()) .content(form.getContent()) .build(); Post saved = this.postRepository.save(_post); return saved; }
PostService { public Post createPost(PostForm form) { Post _post = Post.builder() .title(form.getTitle()) .content(form.getContent()) .build(); Post saved = this.postRepository.save(_post); return saved; } }
PostService { public Post createPost(PostForm form) { Post _post = Post.builder() .title(form.getTitle()) .content(form.getContent()) .build(); Post saved = this.postRepository.save(_post); return saved; } }
PostService { public Post createPost(PostForm form) { Post _post = Post.builder() .title(form.getTitle()) .content(form.getContent()) .build(); Post saved = this.postRepository.save(_post); return saved; } Post createPost(PostForm form); Post updatePost(String slug, PostForm form); void deletePost(String slug); }
PostService { public Post createPost(PostForm form) { Post _post = Post.builder() .title(form.getTitle()) .content(form.getContent()) .build(); Post saved = this.postRepository.save(_post); return saved; } Post createPost(PostForm form); Post updatePost(String slug, PostForm form); void deletePost(String slug); }
@Test public void testFindbyUsername() { this.server.expect(requestTo(userServiceUrl + "/users/user")) .andRespond(withSuccess(new ClassPathResource("/find-user-by-username.json"), MediaType.APPLICATION_JSON_UTF8)); User user = this.client.findByUsername("user"); assertNotNull(user); assertEquals("user", user.getUsername()); this.server.verify(); }
public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); void handleSignup(SignupForm form); User findByUsername(String username); }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); void handleSignup(SignupForm form); User findByUsername(String username); }
@Test public void testFindbyUsername_notFound() { this.server.expect(requestTo(userServiceUrl + "/users/user1")) .andRespond(withStatus(NOT_FOUND)); User user = this.client.findByUsername("user1"); assertNull(user); this.server.verify(); }
public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); void handleSignup(SignupForm form); User findByUsername(String username); }
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); void handleSignup(SignupForm form); User findByUsername(String username); }
@Test public void shouldCreateSmallExportImage() throws IOException { BufferedImage exportedImage = graphExporter.exportCurrentGraph(graph, 1.0, null, null); BufferedImage referenceImage = ImageIO.read(getClass().getResourceAsStream("/export-small.png")); Assert.assertEquals("", TestUtils.bufferedImagesEqual(exportedImage, referenceImage, 10, 100, 10)); }
public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
@Test public void shouldCreateMediumExportImage() throws IOException { BufferedImage exportedImage = graphExporter.exportCurrentGraph(graph, 2.0, null, null); BufferedImage referenceImage = ImageIO.read(getClass().getResourceAsStream("/export-medium.png")); Assert.assertEquals("", TestUtils.bufferedImagesEqual(exportedImage, referenceImage, 10, 300, 10)); }
public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
@Test public void shouldCreateLargeExportImage() throws IOException { BufferedImage exportedImage = graphExporter.exportCurrentGraph(graph, 3.0, null, null); BufferedImage referenceImage = ImageIO.read(getClass().getResourceAsStream("/export-large.png")); Assert.assertEquals("", TestUtils.bufferedImagesEqual(exportedImage, referenceImage, 10, 800, 10)); }
public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
@Test public void shouldPerformBatchExport() throws InterruptedException { String code = "public class shouldPerformBatchExportClass { int test(int a) { " + " if (a < 10) { " + " a = 20; " + " } " + " return a*2; " + " } }"; CodeProcessor codeProcessor = new CodeProcessor(code); GraphBuilder builder = new GraphBuilder(codeProcessor.getPath(), codeProcessor.getClassName()); SimpleBlockGraph blockGraph = builder.buildGraph("int test(int)"); WorklistManager manager = WorklistManager.getInstance(); final DFAExecution<DummyElement> dfa = new DFAExecution<DummyElement>(new DummyFactory(), manager.getWorklist(manager.getWorklistNames().get(0), blockGraph), blockGraph, new DFAPrecalcController()); dfa.setCurrentBlockStep(0); final TestGraphExportCallback testCallback = new TestGraphExportCallback(); new Thread(new Runnable() { @Override public void run() { graphExporter.batchExportAsync(dfa, 1.0, true, testCallback); } }).start(); synchronized (lock) { lock.wait(); } ArrayList<BufferedImage> imageList = testCallback.images; assertEquals(dfa.getTotalElementarySteps() + 1, testCallback.maxStep); assertEquals(dfa.getTotalElementarySteps(), imageList.size()); assertTrue(TestUtils.deltaEqual(603, imageList.get(0).getWidth(), 60)); assertTrue(TestUtils.deltaEqual(299, imageList.get(0).getHeight(), 60)); for (int i = 0; i < dfa.getTotalElementarySteps(); i++) { assertEquals(i, (int) testCallback.steps.get(i)); } final TestGraphExportCallback blockTestCallback = new TestGraphExportCallback(); new Thread(new Runnable() { @Override public void run() { graphExporter.batchExportAsync(dfa, 3.0, false, blockTestCallback); } }).start(); synchronized (lock) { lock.wait(); } ArrayList<BufferedImage> blockImageList = blockTestCallback.images; assertEquals(dfa.getTotalBlockSteps() + 1, blockTestCallback.maxStep); assertEquals(dfa.getTotalBlockSteps(), blockImageList.size()); assertTrue(TestUtils.deltaEqual(1729, blockImageList.get(0).getWidth(), 180)); assertTrue(TestUtils.deltaEqual(895, blockImageList.get(0).getHeight(), 180)); for (int i = 0; i < dfa.getTotalBlockSteps(); i++) { assertEquals(i, (int) blockTestCallback.steps.get(i)); } }
public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
@Test public void graphBatchExportThreadShouldWork() throws InterruptedException { new GraphBatchExportThread(mockExporter, dfa, 3.0, false, null).run(); verify(mockExporter, times(1)).batchExportAsync(dfa, 3.0, false, null); }
public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); }
@Test(expected = IllegalStateException.class) public void refreshShouldNotBePossibleBeforeStart() { controller.refresh(); }
public void refresh() { if (dfa == null) { throw new IllegalStateException("Graph has not been built using start() yet."); } panel.renderGraph(dfa); if (!panel.isJumpToActionEnabled()) { updateStatePanel(); } }
GraphUIController { public void refresh() { if (dfa == null) { throw new IllegalStateException("Graph has not been built using start() yet."); } panel.renderGraph(dfa); if (!panel.isJumpToActionEnabled()) { updateStatePanel(); } } }
GraphUIController { public void refresh() { if (dfa == null) { throw new IllegalStateException("Graph has not been built using start() yet."); } panel.renderGraph(dfa); if (!panel.isJumpToActionEnabled()) { updateStatePanel(); } } GraphUIController(VisualGraphPanel panel); }
GraphUIController { public void refresh() { if (dfa == null) { throw new IllegalStateException("Graph has not been built using start() yet."); } panel.renderGraph(dfa); if (!panel.isJumpToActionEnabled()) { updateStatePanel(); } } GraphUIController(VisualGraphPanel panel); void start(final DFAExecution<? extends LatticeElement> dfa); void setStatePanel(StatePanelOpen statePanel); void refresh(); void stop(); }
GraphUIController { public void refresh() { if (dfa == null) { throw new IllegalStateException("Graph has not been built using start() yet."); } panel.renderGraph(dfa); if (!panel.isJumpToActionEnabled()) { updateStatePanel(); } } GraphUIController(VisualGraphPanel panel); void start(final DFAExecution<? extends LatticeElement> dfa); void setStatePanel(StatePanelOpen statePanel); void refresh(); void stop(); }
@Test(expected = IllegalStateException.class) public void startShouldNotBePossibleTwice() { CodeProcessor codeProcessor = new CodeProcessor("void emptyInside() {}"); GraphBuilder builder = new GraphBuilder(codeProcessor.getPath(), codeProcessor.getClassName()); SimpleBlockGraph blockGraph = builder.buildGraph("void emptyInside()"); DFAExecution<DummyElement> dfa = new DFAExecution<>(new DummyFactory(), new NaiveWorklist(), blockGraph, new DFAPrecalcController()); controller.start(dfa); controller.start(dfa); }
public void start(final DFAExecution<? extends LatticeElement> dfa) { if (this.dfa != null) { throw new IllegalStateException("Visual graph was already built."); } this.dfa = dfa; ControlFlowGraph dfaGraph = dfa.getCFG(); List<BasicBlock> dfaBasicBlocks = dfaGraph.getBasicBlocks(); Map<BasicBlock, UIBasicBlock> mappedBasicBlocks = new HashMap<>(); final List<UIAbstractBlock> uiBlocks = new ArrayList<>(); final Map<mxCell, UIAbstractBlock> mxCellMap = new HashMap<>(); for (int i = 0; i < dfaBasicBlocks.size(); i++) { BasicBlock dfaBasicBlock = dfaBasicBlocks.get(i); UIBasicBlock basicBlock = new UIBasicBlock(graph, dfaBasicBlock, dfa); uiBlocks.add(basicBlock); basicBlock.setBlockNumber(i); List<ElementaryBlock> elementaryBlocks = dfaBasicBlock.getElementaryBlocks(); if (elementaryBlocks.size() != 0) { List<UILineBlock> lineBlocks = new ArrayList<>(); ElementaryBlock firstElementaryBlock = elementaryBlocks.get(0); UILineBlock firstLineBlock = new UILineBlock(firstElementaryBlock, panel.getGraphComponent(), graph, basicBlock); lineBlocks.add(firstLineBlock); uiBlocks.add(firstLineBlock); firstLineBlock.setBlockNumber(0); basicBlock.insertLineBlock(lineBlocks.get(0)); mappedAbstractBlocks.put(firstElementaryBlock, firstLineBlock); for (int n = 1; n < elementaryBlocks.size(); n++) { ElementaryBlock currentElementaryBlock = elementaryBlocks.get(n); UILineBlock newLineBlock = new UILineBlock(currentElementaryBlock, panel.getGraphComponent(), graph, basicBlock, lineBlocks.get(n - 1)); lineBlocks.add(newLineBlock); uiBlocks.add(newLineBlock); newLineBlock.setBlockNumber(n); basicBlock.insertLineBlock(lineBlocks.get(n)); mappedAbstractBlocks.put(currentElementaryBlock, newLineBlock); } } mappedAbstractBlocks.put(dfaBasicBlock, basicBlock); mappedBasicBlocks.put(dfaBasicBlock, basicBlock); panel.insertBasicBlock(basicBlock); } panel.setBlockMap(mappedAbstractBlocks); for (BasicBlock dfaBasicBlock : dfaBasicBlocks) { UIBasicBlock currentBlock = mappedBasicBlocks.get(dfaBasicBlock); List<UIBasicBlock> successors = new ArrayList<>(); for (BasicBlock dfaSuccessor : dfaGraph.getSuccessors(dfaBasicBlock)) { successors.add(mappedBasicBlocks.get(dfaSuccessor)); } for (UIBasicBlock successor : successors) { panel.insertEdge(new UIEdge(graph, currentBlock, successor)); } } panel.renderGraph(dfa); for (UIAbstractBlock block : uiBlocks) { mxCellMap.put(block.getMxCell(), block); } graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxEventSource.mxIEventListener() { @Override public void invoke(Object o, mxEventObject mxEventObject) { @SuppressWarnings("unchecked") ArrayList<mxCell> selectedCells = (ArrayList<mxCell>) mxEventObject.getProperty("removed"); if (selectedCells != null && selectedCells.size() > 0) { mxCell selectedCell = selectedCells.get(0); panel.setSelectedBlock(mxCellMap.get(selectedCell)); } else { panel.setSelectedBlock(null); } updateStatePanel(); } }); }
GraphUIController { public void start(final DFAExecution<? extends LatticeElement> dfa) { if (this.dfa != null) { throw new IllegalStateException("Visual graph was already built."); } this.dfa = dfa; ControlFlowGraph dfaGraph = dfa.getCFG(); List<BasicBlock> dfaBasicBlocks = dfaGraph.getBasicBlocks(); Map<BasicBlock, UIBasicBlock> mappedBasicBlocks = new HashMap<>(); final List<UIAbstractBlock> uiBlocks = new ArrayList<>(); final Map<mxCell, UIAbstractBlock> mxCellMap = new HashMap<>(); for (int i = 0; i < dfaBasicBlocks.size(); i++) { BasicBlock dfaBasicBlock = dfaBasicBlocks.get(i); UIBasicBlock basicBlock = new UIBasicBlock(graph, dfaBasicBlock, dfa); uiBlocks.add(basicBlock); basicBlock.setBlockNumber(i); List<ElementaryBlock> elementaryBlocks = dfaBasicBlock.getElementaryBlocks(); if (elementaryBlocks.size() != 0) { List<UILineBlock> lineBlocks = new ArrayList<>(); ElementaryBlock firstElementaryBlock = elementaryBlocks.get(0); UILineBlock firstLineBlock = new UILineBlock(firstElementaryBlock, panel.getGraphComponent(), graph, basicBlock); lineBlocks.add(firstLineBlock); uiBlocks.add(firstLineBlock); firstLineBlock.setBlockNumber(0); basicBlock.insertLineBlock(lineBlocks.get(0)); mappedAbstractBlocks.put(firstElementaryBlock, firstLineBlock); for (int n = 1; n < elementaryBlocks.size(); n++) { ElementaryBlock currentElementaryBlock = elementaryBlocks.get(n); UILineBlock newLineBlock = new UILineBlock(currentElementaryBlock, panel.getGraphComponent(), graph, basicBlock, lineBlocks.get(n - 1)); lineBlocks.add(newLineBlock); uiBlocks.add(newLineBlock); newLineBlock.setBlockNumber(n); basicBlock.insertLineBlock(lineBlocks.get(n)); mappedAbstractBlocks.put(currentElementaryBlock, newLineBlock); } } mappedAbstractBlocks.put(dfaBasicBlock, basicBlock); mappedBasicBlocks.put(dfaBasicBlock, basicBlock); panel.insertBasicBlock(basicBlock); } panel.setBlockMap(mappedAbstractBlocks); for (BasicBlock dfaBasicBlock : dfaBasicBlocks) { UIBasicBlock currentBlock = mappedBasicBlocks.get(dfaBasicBlock); List<UIBasicBlock> successors = new ArrayList<>(); for (BasicBlock dfaSuccessor : dfaGraph.getSuccessors(dfaBasicBlock)) { successors.add(mappedBasicBlocks.get(dfaSuccessor)); } for (UIBasicBlock successor : successors) { panel.insertEdge(new UIEdge(graph, currentBlock, successor)); } } panel.renderGraph(dfa); for (UIAbstractBlock block : uiBlocks) { mxCellMap.put(block.getMxCell(), block); } graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxEventSource.mxIEventListener() { @Override public void invoke(Object o, mxEventObject mxEventObject) { @SuppressWarnings("unchecked") ArrayList<mxCell> selectedCells = (ArrayList<mxCell>) mxEventObject.getProperty("removed"); if (selectedCells != null && selectedCells.size() > 0) { mxCell selectedCell = selectedCells.get(0); panel.setSelectedBlock(mxCellMap.get(selectedCell)); } else { panel.setSelectedBlock(null); } updateStatePanel(); } }); } }
GraphUIController { public void start(final DFAExecution<? extends LatticeElement> dfa) { if (this.dfa != null) { throw new IllegalStateException("Visual graph was already built."); } this.dfa = dfa; ControlFlowGraph dfaGraph = dfa.getCFG(); List<BasicBlock> dfaBasicBlocks = dfaGraph.getBasicBlocks(); Map<BasicBlock, UIBasicBlock> mappedBasicBlocks = new HashMap<>(); final List<UIAbstractBlock> uiBlocks = new ArrayList<>(); final Map<mxCell, UIAbstractBlock> mxCellMap = new HashMap<>(); for (int i = 0; i < dfaBasicBlocks.size(); i++) { BasicBlock dfaBasicBlock = dfaBasicBlocks.get(i); UIBasicBlock basicBlock = new UIBasicBlock(graph, dfaBasicBlock, dfa); uiBlocks.add(basicBlock); basicBlock.setBlockNumber(i); List<ElementaryBlock> elementaryBlocks = dfaBasicBlock.getElementaryBlocks(); if (elementaryBlocks.size() != 0) { List<UILineBlock> lineBlocks = new ArrayList<>(); ElementaryBlock firstElementaryBlock = elementaryBlocks.get(0); UILineBlock firstLineBlock = new UILineBlock(firstElementaryBlock, panel.getGraphComponent(), graph, basicBlock); lineBlocks.add(firstLineBlock); uiBlocks.add(firstLineBlock); firstLineBlock.setBlockNumber(0); basicBlock.insertLineBlock(lineBlocks.get(0)); mappedAbstractBlocks.put(firstElementaryBlock, firstLineBlock); for (int n = 1; n < elementaryBlocks.size(); n++) { ElementaryBlock currentElementaryBlock = elementaryBlocks.get(n); UILineBlock newLineBlock = new UILineBlock(currentElementaryBlock, panel.getGraphComponent(), graph, basicBlock, lineBlocks.get(n - 1)); lineBlocks.add(newLineBlock); uiBlocks.add(newLineBlock); newLineBlock.setBlockNumber(n); basicBlock.insertLineBlock(lineBlocks.get(n)); mappedAbstractBlocks.put(currentElementaryBlock, newLineBlock); } } mappedAbstractBlocks.put(dfaBasicBlock, basicBlock); mappedBasicBlocks.put(dfaBasicBlock, basicBlock); panel.insertBasicBlock(basicBlock); } panel.setBlockMap(mappedAbstractBlocks); for (BasicBlock dfaBasicBlock : dfaBasicBlocks) { UIBasicBlock currentBlock = mappedBasicBlocks.get(dfaBasicBlock); List<UIBasicBlock> successors = new ArrayList<>(); for (BasicBlock dfaSuccessor : dfaGraph.getSuccessors(dfaBasicBlock)) { successors.add(mappedBasicBlocks.get(dfaSuccessor)); } for (UIBasicBlock successor : successors) { panel.insertEdge(new UIEdge(graph, currentBlock, successor)); } } panel.renderGraph(dfa); for (UIAbstractBlock block : uiBlocks) { mxCellMap.put(block.getMxCell(), block); } graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxEventSource.mxIEventListener() { @Override public void invoke(Object o, mxEventObject mxEventObject) { @SuppressWarnings("unchecked") ArrayList<mxCell> selectedCells = (ArrayList<mxCell>) mxEventObject.getProperty("removed"); if (selectedCells != null && selectedCells.size() > 0) { mxCell selectedCell = selectedCells.get(0); panel.setSelectedBlock(mxCellMap.get(selectedCell)); } else { panel.setSelectedBlock(null); } updateStatePanel(); } }); } GraphUIController(VisualGraphPanel panel); }
GraphUIController { public void start(final DFAExecution<? extends LatticeElement> dfa) { if (this.dfa != null) { throw new IllegalStateException("Visual graph was already built."); } this.dfa = dfa; ControlFlowGraph dfaGraph = dfa.getCFG(); List<BasicBlock> dfaBasicBlocks = dfaGraph.getBasicBlocks(); Map<BasicBlock, UIBasicBlock> mappedBasicBlocks = new HashMap<>(); final List<UIAbstractBlock> uiBlocks = new ArrayList<>(); final Map<mxCell, UIAbstractBlock> mxCellMap = new HashMap<>(); for (int i = 0; i < dfaBasicBlocks.size(); i++) { BasicBlock dfaBasicBlock = dfaBasicBlocks.get(i); UIBasicBlock basicBlock = new UIBasicBlock(graph, dfaBasicBlock, dfa); uiBlocks.add(basicBlock); basicBlock.setBlockNumber(i); List<ElementaryBlock> elementaryBlocks = dfaBasicBlock.getElementaryBlocks(); if (elementaryBlocks.size() != 0) { List<UILineBlock> lineBlocks = new ArrayList<>(); ElementaryBlock firstElementaryBlock = elementaryBlocks.get(0); UILineBlock firstLineBlock = new UILineBlock(firstElementaryBlock, panel.getGraphComponent(), graph, basicBlock); lineBlocks.add(firstLineBlock); uiBlocks.add(firstLineBlock); firstLineBlock.setBlockNumber(0); basicBlock.insertLineBlock(lineBlocks.get(0)); mappedAbstractBlocks.put(firstElementaryBlock, firstLineBlock); for (int n = 1; n < elementaryBlocks.size(); n++) { ElementaryBlock currentElementaryBlock = elementaryBlocks.get(n); UILineBlock newLineBlock = new UILineBlock(currentElementaryBlock, panel.getGraphComponent(), graph, basicBlock, lineBlocks.get(n - 1)); lineBlocks.add(newLineBlock); uiBlocks.add(newLineBlock); newLineBlock.setBlockNumber(n); basicBlock.insertLineBlock(lineBlocks.get(n)); mappedAbstractBlocks.put(currentElementaryBlock, newLineBlock); } } mappedAbstractBlocks.put(dfaBasicBlock, basicBlock); mappedBasicBlocks.put(dfaBasicBlock, basicBlock); panel.insertBasicBlock(basicBlock); } panel.setBlockMap(mappedAbstractBlocks); for (BasicBlock dfaBasicBlock : dfaBasicBlocks) { UIBasicBlock currentBlock = mappedBasicBlocks.get(dfaBasicBlock); List<UIBasicBlock> successors = new ArrayList<>(); for (BasicBlock dfaSuccessor : dfaGraph.getSuccessors(dfaBasicBlock)) { successors.add(mappedBasicBlocks.get(dfaSuccessor)); } for (UIBasicBlock successor : successors) { panel.insertEdge(new UIEdge(graph, currentBlock, successor)); } } panel.renderGraph(dfa); for (UIAbstractBlock block : uiBlocks) { mxCellMap.put(block.getMxCell(), block); } graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxEventSource.mxIEventListener() { @Override public void invoke(Object o, mxEventObject mxEventObject) { @SuppressWarnings("unchecked") ArrayList<mxCell> selectedCells = (ArrayList<mxCell>) mxEventObject.getProperty("removed"); if (selectedCells != null && selectedCells.size() > 0) { mxCell selectedCell = selectedCells.get(0); panel.setSelectedBlock(mxCellMap.get(selectedCell)); } else { panel.setSelectedBlock(null); } updateStatePanel(); } }); } GraphUIController(VisualGraphPanel panel); void start(final DFAExecution<? extends LatticeElement> dfa); void setStatePanel(StatePanelOpen statePanel); void refresh(); void stop(); }
GraphUIController { public void start(final DFAExecution<? extends LatticeElement> dfa) { if (this.dfa != null) { throw new IllegalStateException("Visual graph was already built."); } this.dfa = dfa; ControlFlowGraph dfaGraph = dfa.getCFG(); List<BasicBlock> dfaBasicBlocks = dfaGraph.getBasicBlocks(); Map<BasicBlock, UIBasicBlock> mappedBasicBlocks = new HashMap<>(); final List<UIAbstractBlock> uiBlocks = new ArrayList<>(); final Map<mxCell, UIAbstractBlock> mxCellMap = new HashMap<>(); for (int i = 0; i < dfaBasicBlocks.size(); i++) { BasicBlock dfaBasicBlock = dfaBasicBlocks.get(i); UIBasicBlock basicBlock = new UIBasicBlock(graph, dfaBasicBlock, dfa); uiBlocks.add(basicBlock); basicBlock.setBlockNumber(i); List<ElementaryBlock> elementaryBlocks = dfaBasicBlock.getElementaryBlocks(); if (elementaryBlocks.size() != 0) { List<UILineBlock> lineBlocks = new ArrayList<>(); ElementaryBlock firstElementaryBlock = elementaryBlocks.get(0); UILineBlock firstLineBlock = new UILineBlock(firstElementaryBlock, panel.getGraphComponent(), graph, basicBlock); lineBlocks.add(firstLineBlock); uiBlocks.add(firstLineBlock); firstLineBlock.setBlockNumber(0); basicBlock.insertLineBlock(lineBlocks.get(0)); mappedAbstractBlocks.put(firstElementaryBlock, firstLineBlock); for (int n = 1; n < elementaryBlocks.size(); n++) { ElementaryBlock currentElementaryBlock = elementaryBlocks.get(n); UILineBlock newLineBlock = new UILineBlock(currentElementaryBlock, panel.getGraphComponent(), graph, basicBlock, lineBlocks.get(n - 1)); lineBlocks.add(newLineBlock); uiBlocks.add(newLineBlock); newLineBlock.setBlockNumber(n); basicBlock.insertLineBlock(lineBlocks.get(n)); mappedAbstractBlocks.put(currentElementaryBlock, newLineBlock); } } mappedAbstractBlocks.put(dfaBasicBlock, basicBlock); mappedBasicBlocks.put(dfaBasicBlock, basicBlock); panel.insertBasicBlock(basicBlock); } panel.setBlockMap(mappedAbstractBlocks); for (BasicBlock dfaBasicBlock : dfaBasicBlocks) { UIBasicBlock currentBlock = mappedBasicBlocks.get(dfaBasicBlock); List<UIBasicBlock> successors = new ArrayList<>(); for (BasicBlock dfaSuccessor : dfaGraph.getSuccessors(dfaBasicBlock)) { successors.add(mappedBasicBlocks.get(dfaSuccessor)); } for (UIBasicBlock successor : successors) { panel.insertEdge(new UIEdge(graph, currentBlock, successor)); } } panel.renderGraph(dfa); for (UIAbstractBlock block : uiBlocks) { mxCellMap.put(block.getMxCell(), block); } graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxEventSource.mxIEventListener() { @Override public void invoke(Object o, mxEventObject mxEventObject) { @SuppressWarnings("unchecked") ArrayList<mxCell> selectedCells = (ArrayList<mxCell>) mxEventObject.getProperty("removed"); if (selectedCells != null && selectedCells.size() > 0) { mxCell selectedCell = selectedCells.get(0); panel.setSelectedBlock(mxCellMap.get(selectedCell)); } else { panel.setSelectedBlock(null); } updateStatePanel(); } }); } GraphUIController(VisualGraphPanel panel); void start(final DFAExecution<? extends LatticeElement> dfa); void setStatePanel(StatePanelOpen statePanel); void refresh(); void stop(); }
@Test public void spanFromPayload_startsTraceOnNullPayload() { assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), null)) .isNotNull(); }
Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin( String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin( String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); }
@Test public void spanFromPayload_startsTraceOnAbsentB3SingleEntry() { assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), Collections.emptyMap())) .isNotNull(); }
Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin( String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin( String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); }
@Test public void spanFromPayload_resumesTraceOnB3SingleEntry() { assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), Collections.singletonMap("b3", ByteBuffer.wrap(new byte[] {'0'})))) .extracting(b -> b.isNoop()) .isEqualTo(Boolean.TRUE); }
Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin( String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); }
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin( String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); }
@Test public void testConnect() throws Exception { directedGraph.connect("F", "G", 1d); assertEquals("F", directedGraph.incomingEdgesOf("G").iterator().next().getVertex1()); }
@Override public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new DirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new DirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new DirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new DirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new DirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); }
@Test public void testEdgesWithDisconnectedVertices() throws Exception { graph.add("X"); graph.add("Y"); testGraphEdges(); }
@Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void testAdd() throws Exception { graph.add("X"); Set vertices = Sets.newHashSet(graph.vertices()); assertTrue(vertices.contains("X")); assertTrue(vertices.size()==size+1); }
@Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void testRemove() throws Exception { graph.remove("v1"); assertFalse(Sets.newHashSet(graph.vertices()).contains("v1")); }
@Override public boolean remove(V v){ Set<GraphEdge<V, E>> edges = this.connected.get(v); if (edges == null) return false; for(Iterator<GraphEdge<V,E>> it = edges.iterator(); it.hasNext(); ){ GraphEdge<V,E> edge = it.next(); it.remove(); V v2 = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); for(Iterator<GraphEdge<V,E>> it2 = this.connected.get(v2).iterator(); it2.hasNext();){ GraphEdge<V,E> edge2 = it2.next(); if (edge2.getVertex1().equals(v) || edge2.getVertex2().equals(v)){ it2.remove(); } } } this.connected.remove(v); return true; }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean remove(V v){ Set<GraphEdge<V, E>> edges = this.connected.get(v); if (edges == null) return false; for(Iterator<GraphEdge<V,E>> it = edges.iterator(); it.hasNext(); ){ GraphEdge<V,E> edge = it.next(); it.remove(); V v2 = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); for(Iterator<GraphEdge<V,E>> it2 = this.connected.get(v2).iterator(); it2.hasNext();){ GraphEdge<V,E> edge2 = it2.next(); if (edge2.getVertex1().equals(v) || edge2.getVertex2().equals(v)){ it2.remove(); } } } this.connected.remove(v); return true; } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean remove(V v){ Set<GraphEdge<V, E>> edges = this.connected.get(v); if (edges == null) return false; for(Iterator<GraphEdge<V,E>> it = edges.iterator(); it.hasNext(); ){ GraphEdge<V,E> edge = it.next(); it.remove(); V v2 = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); for(Iterator<GraphEdge<V,E>> it2 = this.connected.get(v2).iterator(); it2.hasNext();){ GraphEdge<V,E> edge2 = it2.next(); if (edge2.getVertex1().equals(v) || edge2.getVertex2().equals(v)){ it2.remove(); } } } this.connected.remove(v); return true; } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean remove(V v){ Set<GraphEdge<V, E>> edges = this.connected.get(v); if (edges == null) return false; for(Iterator<GraphEdge<V,E>> it = edges.iterator(); it.hasNext(); ){ GraphEdge<V,E> edge = it.next(); it.remove(); V v2 = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); for(Iterator<GraphEdge<V,E>> it2 = this.connected.get(v2).iterator(); it2.hasNext();){ GraphEdge<V,E> edge2 = it2.next(); if (edge2.getVertex1().equals(v) || edge2.getVertex2().equals(v)){ it2.remove(); } } } this.connected.remove(v); return true; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean remove(V v){ Set<GraphEdge<V, E>> edges = this.connected.get(v); if (edges == null) return false; for(Iterator<GraphEdge<V,E>> it = edges.iterator(); it.hasNext(); ){ GraphEdge<V,E> edge = it.next(); it.remove(); V v2 = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); for(Iterator<GraphEdge<V,E>> it2 = this.connected.get(v2).iterator(); it2.hasNext();){ GraphEdge<V,E> edge2 = it2.next(); if (edge2.getVertex1().equals(v) || edge2.getVertex2().equals(v)){ it2.remove(); } } } this.connected.remove(v); return true; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void testConnect() throws Exception { graph.add("X"); graph.add("Y"); graph.connect("X","Y",1.0d); assertTrue(Sets.newHashSet(graph.vertices()).contains("X")); assertTrue(Sets.newHashSet(graph.vertices()).contains("Y")); }
@Override public GraphEdge<V,E> connect(V v1, V v2, E value){ if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void testVertices() throws Exception { Set vertices = Sets.newHashSet(graph.vertices()); assertEquals(size, vertices.size()); }
@Override public Iterable<V> vertices() { return connected.keySet(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<V> vertices() { return connected.keySet(); } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<V> vertices() { return connected.keySet(); } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<V> vertices() { return connected.keySet(); } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<V> vertices() { return connected.keySet(); } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void testEdgesOf() throws Exception { Set edges = Sets.newHashSet(graph.edgesOf("v1")); assertEquals(size-1, edges.size()); }
@Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { Set<GraphEdge<V, E>> set = connected.get(vertex); if (set == null) set = Collections.emptySet(); return set; }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { Set<GraphEdge<V, E>> set = connected.get(vertex); if (set == null) set = Collections.emptySet(); return set; } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { Set<GraphEdge<V, E>> set = connected.get(vertex); if (set == null) set = Collections.emptySet(); return set; } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { Set<GraphEdge<V, E>> set = connected.get(vertex); if (set == null) set = Collections.emptySet(); return set; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { Set<GraphEdge<V, E>> set = connected.get(vertex); if (set == null) set = Collections.emptySet(); return set; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void testOutgoingEdgesOf() throws Exception { for(int i=0; i<size; i++) { Set edges = Sets.newHashSet(graph.outgoingEdgesOf("v"+i)); assertEquals(size-(i+1), edges.size()); } }
@Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex1().equals(vertex); } }); }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex1().equals(vertex); } }); } }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex1().equals(vertex); } }); } }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex1().equals(vertex); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex1().equals(vertex); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); }
@Test public void testIncomingEdgesOf() throws Exception { for(int i=0; i<size; i++) { Set edges = Sets.newHashSet(graph.incomingEdgesOf("v"+i)); assertEquals(i, edges.size()); } }
@Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex2().equals(vertex); } }); }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex2().equals(vertex); } }); } }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex2().equals(vertex); } }); } }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex2().equals(vertex); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex2().equals(vertex); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); }
@Test public void testEdges() throws Exception { Set edges = Sets.newHashSet(graph.edges()); assertEquals(size*(size-1)/2, edges.size()); }
@Override public Iterable<GraphEdge<V, E>> edges() { return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); } }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); } }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); }
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); }
@Test public void testOutgoingEdgesOf() throws Exception { Set<DirectedEdge<String, Double>> expected = new HashSet<DirectedEdge<String, Double>>(); expected.add(new DirectedEdge<String, Double>("B", "C", 5d)); expected.add(new DirectedEdge<String, Double>("B", "D", 10d)); assertEquals(expected, Sets.newHashSet(directedGraph.outgoingEdgesOf("B"))); }
@Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) { return graphTable.row(vertex).values(); }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) { return graphTable.row(vertex).values(); } }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) { return graphTable.row(vertex).values(); } }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) { return graphTable.row(vertex).values(); } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) { return graphTable.row(vertex).values(); } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); }
@Test public void testIncomingEdgesOf() throws Exception { Set<DirectedEdge<String, Double>> expected = new HashSet<DirectedEdge<String, Double>>(); expected.add(new DirectedEdge<String, Double>("B", "C", 5d)); expected.add(new DirectedEdge<String, Double>("A", "C", 2d)); assertEquals(expected, Sets.newHashSet(directedGraph.incomingEdgesOf("C"))); }
@Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex) { return graphTable.column(vertex).values(); }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex) { return graphTable.column(vertex).values(); } }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex) { return graphTable.column(vertex).values(); } }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex) { return graphTable.column(vertex).values(); } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); }
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex) { return graphTable.column(vertex).values(); } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); }
@Test public void testAdd() throws Exception { graph.add("G"); assertTrue(Sets.newHashSet(graph.vertices()).contains("G")); }
public void add(V v){ if (!graphTable.containsColumn(v) && !graphTable.containsRow(v)){ disconnected.add(v); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void add(V v){ if (!graphTable.containsColumn(v) && !graphTable.containsRow(v)){ disconnected.add(v); } } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void add(V v){ if (!graphTable.containsColumn(v) && !graphTable.containsRow(v)){ disconnected.add(v); } } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void add(V v){ if (!graphTable.containsColumn(v) && !graphTable.containsRow(v)){ disconnected.add(v); } } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void add(V v){ if (!graphTable.containsColumn(v) && !graphTable.containsRow(v)){ disconnected.add(v); } } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
@Test public void testRemove() throws Exception { graph.remove("B"); assertFalse(Sets.newHashSet(graph.vertices()).contains("B")); }
public void remove(V v){ for(GraphEdge<V,E> edge : edgesOf(v)){ V connectedVertex = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); if (!greaterThan(1, edgesOf(connectedVertex))){ disconnected.add(connectedVertex); } } if (graphTable.containsRow(v)){ graphTable.row(v).clear(); } if (graphTable.containsColumn(v)){ graphTable.column(v).clear(); } disconnected.remove(v); }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void remove(V v){ for(GraphEdge<V,E> edge : edgesOf(v)){ V connectedVertex = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); if (!greaterThan(1, edgesOf(connectedVertex))){ disconnected.add(connectedVertex); } } if (graphTable.containsRow(v)){ graphTable.row(v).clear(); } if (graphTable.containsColumn(v)){ graphTable.column(v).clear(); } disconnected.remove(v); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void remove(V v){ for(GraphEdge<V,E> edge : edgesOf(v)){ V connectedVertex = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); if (!greaterThan(1, edgesOf(connectedVertex))){ disconnected.add(connectedVertex); } } if (graphTable.containsRow(v)){ graphTable.row(v).clear(); } if (graphTable.containsColumn(v)){ graphTable.column(v).clear(); } disconnected.remove(v); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void remove(V v){ for(GraphEdge<V,E> edge : edgesOf(v)){ V connectedVertex = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); if (!greaterThan(1, edgesOf(connectedVertex))){ disconnected.add(connectedVertex); } } if (graphTable.containsRow(v)){ graphTable.row(v).clear(); } if (graphTable.containsColumn(v)){ graphTable.column(v).clear(); } disconnected.remove(v); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { public void remove(V v){ for(GraphEdge<V,E> edge : edgesOf(v)){ V connectedVertex = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); if (!greaterThan(1, edgesOf(connectedVertex))){ disconnected.add(connectedVertex); } } if (graphTable.containsRow(v)){ graphTable.row(v).clear(); } if (graphTable.containsColumn(v)){ graphTable.column(v).clear(); } disconnected.remove(v); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
@Test public void testConnect() throws Exception { graph.connect("X","Y",1.0d); assertTrue(Sets.newHashSet(graph.vertices()).contains("X")); assertTrue(Sets.newHashSet(graph.vertices()).contains("Y")); }
public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new UndirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); graphTable.put(v2, v1, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; }
HashTableHipsterGraph implements HipsterGraph<V,E> { public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new UndirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); graphTable.put(v2, v1, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new UndirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); graphTable.put(v2, v1, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } }
HashTableHipsterGraph implements HipsterGraph<V,E> { public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new UndirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); graphTable.put(v2, v1, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new UndirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); graphTable.put(v2, v1, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
@Test public void testEdges() throws Exception { Set<GraphEdge<String,Double>> expected = new HashSet<GraphEdge<String, Double>>(); expected.add(new UndirectedEdge<String, Double>("A","B",4d)); expected.add(new UndirectedEdge<String, Double>("A","C",2d)); expected.add(new UndirectedEdge<String, Double>("B","C",5d)); expected.add(new UndirectedEdge<String, Double>("B","D",10d)); expected.add(new UndirectedEdge<String, Double>("C","E",3d)); expected.add(new UndirectedEdge<String, Double>("D","F",11d)); expected.add(new UndirectedEdge<String, Double>("E","D",4d)); assertEquals(expected, Sets.newHashSet(graph.edges())); }
@Override public Iterable<GraphEdge<V, E>> edges() { return graphTable.values(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return graphTable.values(); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return graphTable.values(); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return graphTable.values(); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return graphTable.values(); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
@Test public void testVertices() throws Exception { Set<String> expected = Sets.newHashSet("A","B","C","D","E","F"); assertEquals(expected, graph.vertices()); }
@Override public Iterable<V> vertices() { return Sets.union(Sets.union(graphTable.rowKeySet(), graphTable.columnKeySet()), disconnected); }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<V> vertices() { return Sets.union(Sets.union(graphTable.rowKeySet(), graphTable.columnKeySet()), disconnected); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<V> vertices() { return Sets.union(Sets.union(graphTable.rowKeySet(), graphTable.columnKeySet()), disconnected); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<V> vertices() { return Sets.union(Sets.union(graphTable.rowKeySet(), graphTable.columnKeySet()), disconnected); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<V> vertices() { return Sets.union(Sets.union(graphTable.rowKeySet(), graphTable.columnKeySet()), disconnected); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
@Test public void testEdgesOf() throws Exception { Set<GraphEdge<String,Double>> expected = new HashSet<GraphEdge<String, Double>>(); expected.add(new UndirectedEdge<String, Double>("B","D",10d)); expected.add(new UndirectedEdge<String, Double>("A","B",4d)); expected.add(new UndirectedEdge<String, Double>("B","C",5d)); assertEquals(expected, graph.edgesOf("B")); }
@Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { return Sets.union(Sets.newHashSet(graphTable.row(vertex).values()), Sets.newHashSet(graphTable.column(vertex).values())); }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { return Sets.union(Sets.newHashSet(graphTable.row(vertex).values()), Sets.newHashSet(graphTable.column(vertex).values())); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { return Sets.union(Sets.newHashSet(graphTable.row(vertex).values()), Sets.newHashSet(graphTable.column(vertex).values())); } }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { return Sets.union(Sets.newHashSet(graphTable.row(vertex).values()), Sets.newHashSet(graphTable.column(vertex).values())); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { return Sets.union(Sets.newHashSet(graphTable.row(vertex).values()), Sets.newHashSet(graphTable.column(vertex).values())); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); }
@Test public void testEdges() throws Exception { testGraphEdges(); }
@Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); } }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); } HashBasedHipsterGraph(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); }
@Test public void getGasPriceWhenValueIsNull() throws Exception { Web3.CallArguments args = new Web3.CallArguments(); CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args); Assert.assertArrayEquals(new byte[] {0}, byteArrayArgs.getGasPrice()); }
public byte[] getGasPrice() { byte[] gasPrice = new byte[] {0}; if (args.gasPrice != null && args.gasPrice.length() != 0) { gasPrice = stringHexToByteArray(args.gasPrice); } return gasPrice; }
CallArgumentsToByteArray { public byte[] getGasPrice() { byte[] gasPrice = new byte[] {0}; if (args.gasPrice != null && args.gasPrice.length() != 0) { gasPrice = stringHexToByteArray(args.gasPrice); } return gasPrice; } }
CallArgumentsToByteArray { public byte[] getGasPrice() { byte[] gasPrice = new byte[] {0}; if (args.gasPrice != null && args.gasPrice.length() != 0) { gasPrice = stringHexToByteArray(args.gasPrice); } return gasPrice; } CallArgumentsToByteArray(Web3.CallArguments args); }
CallArgumentsToByteArray { public byte[] getGasPrice() { byte[] gasPrice = new byte[] {0}; if (args.gasPrice != null && args.gasPrice.length() != 0) { gasPrice = stringHexToByteArray(args.gasPrice); } return gasPrice; } CallArgumentsToByteArray(Web3.CallArguments args); byte[] getGasPrice(); byte[] getGasLimit(); byte[] getToAddress(); byte[] getValue(); byte[] getData(); RskAddress getFromAddress(); }
CallArgumentsToByteArray { public byte[] getGasPrice() { byte[] gasPrice = new byte[] {0}; if (args.gasPrice != null && args.gasPrice.length() != 0) { gasPrice = stringHexToByteArray(args.gasPrice); } return gasPrice; } CallArgumentsToByteArray(Web3.CallArguments args); byte[] getGasPrice(); byte[] getGasLimit(); byte[] getToAddress(); byte[] getValue(); byte[] getData(); RskAddress getFromAddress(); }
@Test public void serializeLockWhitelist() throws Exception { byte[][] addressesBytes = new byte[][]{ BtcECKey.fromPrivate(BigInteger.valueOf(100)).getPubKeyHash(), BtcECKey.fromPrivate(BigInteger.valueOf(200)).getPubKeyHash(), BtcECKey.fromPrivate(BigInteger.valueOf(300)).getPubKeyHash(), BtcECKey.fromPrivate(BigInteger.valueOf(400)).getPubKeyHash(), BtcECKey.fromPrivate(BigInteger.valueOf(500)).getPubKeyHash(), BtcECKey.fromPrivate(BigInteger.valueOf(600)).getPubKeyHash(), }; Coin maxToTransfer = Coin.CENT; LockWhitelist lockWhitelist = new LockWhitelist( Arrays.stream(addressesBytes) .map(bytes -> new Address(NetworkParameters.fromID(NetworkParameters.ID_REGTEST), bytes)) .collect(Collectors.toMap(Function.identity(), k -> new OneOffWhiteListEntry(k, maxToTransfer))), 0); byte[] result = BridgeSerializationUtils.serializeOneOffLockWhitelist(Pair.of( lockWhitelist.getAll(OneOffWhiteListEntry.class), lockWhitelist.getDisableBlockHeight() )); StringBuilder expectedBuilder = new StringBuilder(); expectedBuilder.append("f897"); Arrays.stream(addressesBytes).sorted(UnsignedBytes.lexicographicalComparator()).forEach(bytes -> { expectedBuilder.append("94"); expectedBuilder.append(ByteUtil.toHexString(bytes)); expectedBuilder.append("83"); expectedBuilder.append(ByteUtil.toHexString(BigInteger.valueOf(maxToTransfer.value).toByteArray())); }); expectedBuilder.append("80"); String expected = expectedBuilder.toString(); Assert.assertEquals(expected, ByteUtil.toHexString(result)); }
public static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data) { List<OneOffWhiteListEntry> entries = data.getLeft(); Integer disableBlockHeight = data.getRight(); int serializationSize = entries.size() * 2 + 1; byte[][] serializedLockWhitelist = new byte[serializationSize][]; for (int i = 0; i < entries.size(); i++) { OneOffWhiteListEntry entry = entries.get(i); serializedLockWhitelist[2 * i] = RLP.encodeElement(entry.address().getHash160()); serializedLockWhitelist[2 * i + 1] = RLP.encodeBigInteger(BigInteger.valueOf(entry.maxTransferValue().longValue())); } serializedLockWhitelist[serializationSize - 1] = RLP.encodeBigInteger(BigInteger.valueOf(disableBlockHeight)); return RLP.encodeList(serializedLockWhitelist); }
BridgeSerializationUtils { public static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data) { List<OneOffWhiteListEntry> entries = data.getLeft(); Integer disableBlockHeight = data.getRight(); int serializationSize = entries.size() * 2 + 1; byte[][] serializedLockWhitelist = new byte[serializationSize][]; for (int i = 0; i < entries.size(); i++) { OneOffWhiteListEntry entry = entries.get(i); serializedLockWhitelist[2 * i] = RLP.encodeElement(entry.address().getHash160()); serializedLockWhitelist[2 * i + 1] = RLP.encodeBigInteger(BigInteger.valueOf(entry.maxTransferValue().longValue())); } serializedLockWhitelist[serializationSize - 1] = RLP.encodeBigInteger(BigInteger.valueOf(disableBlockHeight)); return RLP.encodeList(serializedLockWhitelist); } }
BridgeSerializationUtils { public static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data) { List<OneOffWhiteListEntry> entries = data.getLeft(); Integer disableBlockHeight = data.getRight(); int serializationSize = entries.size() * 2 + 1; byte[][] serializedLockWhitelist = new byte[serializationSize][]; for (int i = 0; i < entries.size(); i++) { OneOffWhiteListEntry entry = entries.get(i); serializedLockWhitelist[2 * i] = RLP.encodeElement(entry.address().getHash160()); serializedLockWhitelist[2 * i + 1] = RLP.encodeBigInteger(BigInteger.valueOf(entry.maxTransferValue().longValue())); } serializedLockWhitelist[serializationSize - 1] = RLP.encodeBigInteger(BigInteger.valueOf(disableBlockHeight)); return RLP.encodeList(serializedLockWhitelist); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data) { List<OneOffWhiteListEntry> entries = data.getLeft(); Integer disableBlockHeight = data.getRight(); int serializationSize = entries.size() * 2 + 1; byte[][] serializedLockWhitelist = new byte[serializationSize][]; for (int i = 0; i < entries.size(); i++) { OneOffWhiteListEntry entry = entries.get(i); serializedLockWhitelist[2 * i] = RLP.encodeElement(entry.address().getHash160()); serializedLockWhitelist[2 * i + 1] = RLP.encodeBigInteger(BigInteger.valueOf(entry.maxTransferValue().longValue())); } serializedLockWhitelist[serializationSize - 1] = RLP.encodeBigInteger(BigInteger.valueOf(disableBlockHeight)); return RLP.encodeList(serializedLockWhitelist); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data) { List<OneOffWhiteListEntry> entries = data.getLeft(); Integer disableBlockHeight = data.getRight(); int serializationSize = entries.size() * 2 + 1; byte[][] serializedLockWhitelist = new byte[serializationSize][]; for (int i = 0; i < entries.size(); i++) { OneOffWhiteListEntry entry = entries.get(i); serializedLockWhitelist[2 * i] = RLP.encodeElement(entry.address().getHash160()); serializedLockWhitelist[2 * i + 1] = RLP.encodeBigInteger(BigInteger.valueOf(entry.maxTransferValue().longValue())); } serializedLockWhitelist[serializationSize - 1] = RLP.encodeBigInteger(BigInteger.valueOf(disableBlockHeight)); return RLP.encodeList(serializedLockWhitelist); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeOneOffLockWhitelistAndDisableBlockHeight() throws Exception { byte[][] addressesBytes = Arrays.asList(100, 200, 300, 400).stream() .map(k -> BtcECKey.fromPrivate(BigInteger.valueOf(k))) .sorted(BtcECKey.PUBKEY_COMPARATOR) .map(k -> k.getPubKeyHash()) .toArray(byte[][]::new); byte[][] rlpBytes = new byte[9][0]; for (int k = 0; k < addressesBytes.length; k++) { rlpBytes[k * 2] = RLP.encodeElement(addressesBytes[k]); rlpBytes[k * 2 + 1] = RLP.encodeElement(Hex.decode("0186a0")); } rlpBytes[8] = RLP.encodeElement(Hex.decode("002a")); byte[] data = RLP.encodeList(rlpBytes); Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializedLockWhitelist = BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight( data, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertThat(deserializedLockWhitelist.getLeft().size(), is(addressesBytes.length)); Assert.assertThat(deserializedLockWhitelist.getLeft().keySet().stream().map(Address::getHash160).collect(Collectors.toList()), containsInAnyOrder(addressesBytes)); Set<Coin> deserializedCoins = deserializedLockWhitelist.getLeft().values().stream().map(entry -> ((OneOffWhiteListEntry)entry).maxTransferValue()).collect(Collectors.toSet()); Assert.assertThat(deserializedCoins, hasSize(1)); Assert.assertThat(deserializedCoins, hasItem(Coin.MILLICOIN)); Assert.assertThat(deserializedLockWhitelist.getRight(), is(42)); }
public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeOneOffLockWhitelistAndDisableBlockHeight_null() throws Exception { Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializedLockWhitelist = BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight( null, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertNull(deserializedLockWhitelist); Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializedLockWhitelist2 = BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight( new byte[]{}, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertNull(deserializedLockWhitelist2); }
public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters) { if (data == null || data.length == 0) { return null; } RLPList rlpList = (RLPList)RLP.decode2(data).get(0); int serializedAddressesSize = rlpList.size() - 1; if (serializedAddressesSize % 2 != 0) { throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given"); } HashMap<Address, OneOffWhiteListEntry> entries = new HashMap<>(serializedAddressesSize / 2); for (int i = 0; i < serializedAddressesSize; i = i + 2) { byte[] hash160 = rlpList.get(i).getRLPData(); byte[] maxTransferValueData = rlpList.get(i + 1).getRLPData(); Address address = new Address(parameters, hash160); entries.put(address, new OneOffWhiteListEntry(address, Coin.valueOf(safeToBigInteger(maxTransferValueData).longValueExact()))); } int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact(); return Pair.of(entries, disableBlockHeight); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void serializeRequestQueue() throws Exception { List<ReleaseRequestQueue.Entry> sampleEntries = Arrays.asList( new ReleaseRequestQueue.Entry(mockAddressHash160("ccdd"), Coin.valueOf(10)), new ReleaseRequestQueue.Entry(mockAddressHash160("bb"), Coin.valueOf(50)), new ReleaseRequestQueue.Entry(mockAddressHash160("bb"), Coin.valueOf(20)), new ReleaseRequestQueue.Entry(mockAddressHash160("aa"), Coin.valueOf(30)) ); ReleaseRequestQueue sample = new ReleaseRequestQueue(sampleEntries); byte[] result = BridgeSerializationUtils.serializeReleaseRequestQueue(sample); String hexResult = ByteUtil.toHexString(result); StringBuilder expectedBuilder = new StringBuilder(); expectedBuilder.append("cd"); expectedBuilder.append("82ccdd"); expectedBuilder.append("0a"); expectedBuilder.append("81bb"); expectedBuilder.append("32"); expectedBuilder.append("81bb"); expectedBuilder.append("14"); expectedBuilder.append("81aa"); expectedBuilder.append("1e"); assertEquals(expectedBuilder.toString(), hexResult); }
public static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue) { List<ReleaseRequestQueue.Entry> entries = queue.getEntriesWithoutHash(); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseRequestQueue.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getDestination().getHash160()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getAmount().getValue())); } return RLP.encodeList(bytes); }
BridgeSerializationUtils { public static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue) { List<ReleaseRequestQueue.Entry> entries = queue.getEntriesWithoutHash(); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseRequestQueue.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getDestination().getHash160()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getAmount().getValue())); } return RLP.encodeList(bytes); } }
BridgeSerializationUtils { public static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue) { List<ReleaseRequestQueue.Entry> entries = queue.getEntriesWithoutHash(); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseRequestQueue.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getDestination().getHash160()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getAmount().getValue())); } return RLP.encodeList(bytes); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue) { List<ReleaseRequestQueue.Entry> entries = queue.getEntriesWithoutHash(); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseRequestQueue.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getDestination().getHash160()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getAmount().getValue())); } return RLP.encodeList(bytes); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue) { List<ReleaseRequestQueue.Entry> entries = queue.getEntriesWithoutHash(); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseRequestQueue.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getDestination().getHash160()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getAmount().getValue())); } return RLP.encodeList(bytes); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeRequestQueue_emptyOrNull() throws Exception { assertEquals(0, BridgeSerializationUtils.deserializeReleaseRequestQueue(null, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)).size()); assertEquals(0, BridgeSerializationUtils.deserializeReleaseRequestQueue(new byte[]{}, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)).size()); }
public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeRequestQueue_nonEmpty() throws Exception { NetworkParameters params = NetworkParameters.fromID(NetworkParameters.ID_REGTEST); Address a1 = Address.fromBase58(params, "mynmcQfJnVjheAqh9XL6htnxPZnaDFbqkB"); Address a2 = Address.fromBase58(params, "mfrfxeo5L2f5NDURS6YTtCNfVw2t5HAfty"); Address a3 = Address.fromBase58(params, "myw7AMh5mpKHao6MArhn7EvkeASGsGJzrZ"); List<ReleaseRequestQueue.Entry> expectedEntries = Arrays.asList( new ReleaseRequestQueue.Entry(a1, Coin.valueOf(10)), new ReleaseRequestQueue.Entry(a2, Coin.valueOf(7)), new ReleaseRequestQueue.Entry(a3, Coin.valueOf(8)) ); byte[][] rlpItems = new byte[6][]; rlpItems[0] = RLP.encodeElement(a1.getHash160()); rlpItems[1] = RLP.encodeBigInteger(BigInteger.valueOf(10)); rlpItems[2] = RLP.encodeElement(a2.getHash160()); rlpItems[3] = RLP.encodeBigInteger(BigInteger.valueOf(7)); rlpItems[4] = RLP.encodeElement(a3.getHash160()); rlpItems[5] = RLP.encodeBigInteger(BigInteger.valueOf(8)); byte[] data = RLP.encodeList(rlpItems); ReleaseRequestQueue result = new ReleaseRequestQueue(BridgeSerializationUtils.deserializeReleaseRequestQueue(data, params)); List<ReleaseRequestQueue.Entry> entries = result.getEntries(); assertEquals(expectedEntries, entries); }
public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeRequestQueue_nonEmptyOddSize() throws Exception { NetworkParameters params = NetworkParameters.fromID(NetworkParameters.ID_REGTEST); Address a1 = Address.fromBase58(params, "mynmcQfJnVjheAqh9XL6htnxPZnaDFbqkB"); Address a2 = Address.fromBase58(params, "mfrfxeo5L2f5NDURS6YTtCNfVw2t5HAfty"); Address a3 = Address.fromBase58(params, "myw7AMh5mpKHao6MArhn7EvkeASGsGJzrZ"); byte[][] rlpItems = new byte[7][]; rlpItems[0] = RLP.encodeElement(a1.getHash160()); rlpItems[1] = RLP.encodeBigInteger(BigInteger.valueOf(10)); rlpItems[2] = RLP.encodeElement(a2.getHash160()); rlpItems[3] = RLP.encodeBigInteger(BigInteger.valueOf(7)); rlpItems[4] = RLP.encodeElement(a3.getHash160()); rlpItems[5] = RLP.encodeBigInteger(BigInteger.valueOf(8)); rlpItems[6] = RLP.encodeBigInteger(BigInteger.valueOf(8)); byte[] data = RLP.encodeList(rlpItems); try { BridgeSerializationUtils.deserializeReleaseRequestQueue(data, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); } catch (RuntimeException e) { return; } Assert.fail(); }
public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseRequestQueue(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void serializeTransactionSet() throws Exception { Set<ReleaseTransactionSet.Entry> sampleEntries = new HashSet<>(Arrays.asList( new ReleaseTransactionSet.Entry(mockBtcTransactionSerialize("ccdd"), 10L), new ReleaseTransactionSet.Entry(mockBtcTransactionSerialize("bb"), 20L), new ReleaseTransactionSet.Entry(mockBtcTransactionSerialize("ba"), 30L), new ReleaseTransactionSet.Entry(mockBtcTransactionSerialize("aa"), 40L) )); ReleaseTransactionSet sample = new ReleaseTransactionSet(sampleEntries); byte[] result = BridgeSerializationUtils.serializeReleaseTransactionSet(sample); String hexResult = ByteUtil.toHexString(result); StringBuilder expectedBuilder = new StringBuilder(); expectedBuilder.append("cd"); expectedBuilder.append("81aa"); expectedBuilder.append("28"); expectedBuilder.append("81ba"); expectedBuilder.append("1e"); expectedBuilder.append("81bb"); expectedBuilder.append("14"); expectedBuilder.append("82ccdd"); expectedBuilder.append("0a"); assertEquals(expectedBuilder.toString(), hexResult); }
public static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set) { List<ReleaseTransactionSet.Entry> entries = set.getEntriesWithoutHash().stream().collect(Collectors.toList()); entries.sort(ReleaseTransactionSet.Entry.BTC_TX_COMPARATOR); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseTransactionSet.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getTransaction().bitcoinSerialize()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getRskBlockNumber())); } return RLP.encodeList(bytes); }
BridgeSerializationUtils { public static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set) { List<ReleaseTransactionSet.Entry> entries = set.getEntriesWithoutHash().stream().collect(Collectors.toList()); entries.sort(ReleaseTransactionSet.Entry.BTC_TX_COMPARATOR); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseTransactionSet.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getTransaction().bitcoinSerialize()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getRskBlockNumber())); } return RLP.encodeList(bytes); } }
BridgeSerializationUtils { public static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set) { List<ReleaseTransactionSet.Entry> entries = set.getEntriesWithoutHash().stream().collect(Collectors.toList()); entries.sort(ReleaseTransactionSet.Entry.BTC_TX_COMPARATOR); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseTransactionSet.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getTransaction().bitcoinSerialize()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getRskBlockNumber())); } return RLP.encodeList(bytes); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set) { List<ReleaseTransactionSet.Entry> entries = set.getEntriesWithoutHash().stream().collect(Collectors.toList()); entries.sort(ReleaseTransactionSet.Entry.BTC_TX_COMPARATOR); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseTransactionSet.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getTransaction().bitcoinSerialize()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getRskBlockNumber())); } return RLP.encodeList(bytes); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set) { List<ReleaseTransactionSet.Entry> entries = set.getEntriesWithoutHash().stream().collect(Collectors.toList()); entries.sort(ReleaseTransactionSet.Entry.BTC_TX_COMPARATOR); byte[][] bytes = new byte[entries.size() * 2][]; int n = 0; for (ReleaseTransactionSet.Entry entry : entries) { bytes[n++] = RLP.encodeElement(entry.getTransaction().bitcoinSerialize()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getRskBlockNumber())); } return RLP.encodeList(bytes); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeTransactionSet_emptyOrNull() throws Exception { assertEquals(0, BridgeSerializationUtils.deserializeReleaseTransactionSet(null, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)).getEntries().size()); assertEquals(0, BridgeSerializationUtils.deserializeReleaseTransactionSet(new byte[]{}, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)).getEntries().size()); }
public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeTransactionSet_nonEmptyOddSize() throws Exception { byte[] firstItem = RLP.encodeElement(Hex.decode("010203")); byte[] data = RLP.encodeList(firstItem); try { BridgeSerializationUtils.deserializeReleaseTransactionSet(data, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); } catch (RuntimeException e) { return; } Assert.fail(); }
public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) { return deserializeReleaseTransactionSet(data, networkParameters, false); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void isEmpty_Array() { Value val = new Value(new String[0]); assertTrue(val.isEmpty()); }
public boolean isEmpty() { if (isNull()) { return true; } if (isBytes() && asBytes().length == 0) { return true; } if (isList() && asList().isEmpty()) { return true; } if (isString() && asString().equals("")) { return true; } return false; }
Value { public boolean isEmpty() { if (isNull()) { return true; } if (isBytes() && asBytes().length == 0) { return true; } if (isList() && asList().isEmpty()) { return true; } if (isString() && asString().equals("")) { return true; } return false; } }
Value { public boolean isEmpty() { if (isNull()) { return true; } if (isBytes() && asBytes().length == 0) { return true; } if (isList() && asList().isEmpty()) { return true; } if (isString() && asString().equals("")) { return true; } return false; } Value(); Value(Object obj); }
Value { public boolean isEmpty() { if (isNull()) { return true; } if (isBytes() && asBytes().length == 0) { return true; } if (isList() && asList().isEmpty()) { return true; } if (isString() && asString().equals("")) { return true; } return false; } Value(); Value(Object obj); static Value fromRlpEncoded(byte[] data); void init(byte[] rlp); Object asObj(); List<Object> asList(); int asInt(); long asLong(); BigInteger asBigInt(); String asString(); byte[] asBytes(); String getHex(); byte[] getData(); int[] asSlice(); Value get(int index); byte[] encode(); byte[] hash(); boolean isList(); boolean isString(); boolean isInt(); boolean isLong(); boolean isBigInt(); boolean isBytes(); boolean isReadableString(); boolean isHexString(); boolean isHashCode(); boolean isNull(); boolean isEmpty(); int length(); String toString(); }
Value { public boolean isEmpty() { if (isNull()) { return true; } if (isBytes() && asBytes().length == 0) { return true; } if (isList() && asList().isEmpty()) { return true; } if (isString() && asString().equals("")) { return true; } return false; } Value(); Value(Object obj); static Value fromRlpEncoded(byte[] data); void init(byte[] rlp); Object asObj(); List<Object> asList(); int asInt(); long asLong(); BigInteger asBigInt(); String asString(); byte[] asBytes(); String getHex(); byte[] getData(); int[] asSlice(); Value get(int index); byte[] encode(); byte[] hash(); boolean isList(); boolean isString(); boolean isInt(); boolean isLong(); boolean isBigInt(); boolean isBytes(); boolean isReadableString(); boolean isHexString(); boolean isHashCode(); boolean isNull(); boolean isEmpty(); int length(); String toString(); }
@Test public void serializeInteger() { Assert.assertEquals(BigInteger.valueOf(123), RLP.decodeBigInteger(BridgeSerializationUtils.serializeInteger(123), 0)); Assert.assertEquals(BigInteger.valueOf(1200), RLP.decodeBigInteger(BridgeSerializationUtils.serializeInteger(1200), 0)); }
public static byte[] serializeInteger(Integer value) { return RLP.encodeBigInteger(BigInteger.valueOf(value)); }
BridgeSerializationUtils { public static byte[] serializeInteger(Integer value) { return RLP.encodeBigInteger(BigInteger.valueOf(value)); } }
BridgeSerializationUtils { public static byte[] serializeInteger(Integer value) { return RLP.encodeBigInteger(BigInteger.valueOf(value)); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static byte[] serializeInteger(Integer value) { return RLP.encodeBigInteger(BigInteger.valueOf(value)); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static byte[] serializeInteger(Integer value) { return RLP.encodeBigInteger(BigInteger.valueOf(value)); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void deserializeInteger() { Assert.assertEquals(123, BridgeSerializationUtils.deserializeInteger(RLP.encodeBigInteger(BigInteger.valueOf(123))).intValue()); Assert.assertEquals(1200, BridgeSerializationUtils.deserializeInteger(RLP.encodeBigInteger(BigInteger.valueOf(1200))).intValue()); }
public static Integer deserializeInteger(byte[] data) { return RLP.decodeBigInteger(data, 0).intValue(); }
BridgeSerializationUtils { public static Integer deserializeInteger(byte[] data) { return RLP.decodeBigInteger(data, 0).intValue(); } }
BridgeSerializationUtils { public static Integer deserializeInteger(byte[] data) { return RLP.decodeBigInteger(data, 0).intValue(); } private BridgeSerializationUtils(); }
BridgeSerializationUtils { public static Integer deserializeInteger(byte[] data) { return RLP.decodeBigInteger(data, 0).intValue(); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
BridgeSerializationUtils { public static Integer deserializeInteger(byte[] data) { return RLP.decodeBigInteger(data, 0).intValue(); } private BridgeSerializationUtils(); static byte[] serializeMap(SortedMap<Keccak256, BtcTransaction> map); static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs); static byte[] serializeUTXOList(List<UTXO> list); static List<UTXO> deserializeUTXOList(byte[] data); static byte[] serializeSet(SortedSet<Sha256Hash> set); static SortedSet<Sha256Hash> deserializeSet(byte[] data); static byte[] serializeMapOfHashesToLong(Map<Sha256Hash, Long> map); static Map<Sha256Hash, Long> deserializeMapOfHashesToLong(byte[] data); static byte[] serializeFederationOnlyBtcKeys(Federation federation); static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederation(Federation federation); static Federation deserializeFederation(byte[] data, NetworkParameters networkParameters); static byte[] serializeFederationMember(FederationMember federationMember); static byte[] serializePendingFederationOnlyBtcKeys(PendingFederation pendingFederation); static PendingFederation deserializePendingFederationOnlyBtcKeys(byte[] data); static byte[] serializePendingFederation(PendingFederation pendingFederation); static PendingFederation deserializePendingFederation(byte[] data); static byte[] serializeElection(ABICallElection election); static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer); static byte[] serializeOneOffLockWhitelist(Pair<List<OneOffWhiteListEntry>, Integer> data); static byte[] serializeUnlimitedLockWhitelist(List<UnlimitedWhiteListEntry> entries); static Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> deserializeOneOffLockWhitelistAndDisableBlockHeight(byte[] data, NetworkParameters parameters); static Map<Address, UnlimitedWhiteListEntry> deserializeUnlimitedLockWhitelistEntries(byte[] data, NetworkParameters parameters); static byte[] serializeCoin(Coin coin); @Nullable static Coin deserializeCoin(byte[] data); static byte[] serializeReleaseRequestQueue(ReleaseRequestQueue queue); static byte[] serializeReleaseRequestQueueWithTxHash(ReleaseRequestQueue queue); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters); static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeReleaseTransactionSet(ReleaseTransactionSet set); static byte[] serializeReleaseTransactionSetWithTxHash(ReleaseTransactionSet set); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters); static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters, boolean hasTxHash); static byte[] serializeInteger(Integer value); static Integer deserializeInteger(byte[] data); static byte[] serializeLong(long value); static Optional<Long> deserializeOptionalLong(byte[] data); static CoinbaseInformation deserializeCoinbaseInformation(byte[] data); static byte[] serializeCoinbaseInformation(CoinbaseInformation coinbaseInformation); }
@Test public void getSize() { Assert.assertEquals(4, whitelist.getSize().intValue()); }
public Integer getSize() { return whitelistedAddresses.size(); }
LockWhitelist { public Integer getSize() { return whitelistedAddresses.size(); } }
LockWhitelist { public Integer getSize() { return whitelistedAddresses.size(); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
LockWhitelist { public Integer getSize() { return whitelistedAddresses.size(); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
LockWhitelist { public Integer getSize() { return whitelistedAddresses.size(); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
@Test public void getAddresses() { Assert.assertNotSame(whitelist.getAddresses(), addresses); Assert.assertThat(whitelist.getAddresses(), containsInAnyOrder(addresses.keySet().toArray())); }
public List<Address> getAddresses() { return new ArrayList<>(whitelistedAddresses.keySet()); }
LockWhitelist { public List<Address> getAddresses() { return new ArrayList<>(whitelistedAddresses.keySet()); } }
LockWhitelist { public List<Address> getAddresses() { return new ArrayList<>(whitelistedAddresses.keySet()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
LockWhitelist { public List<Address> getAddresses() { return new ArrayList<>(whitelistedAddresses.keySet()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
LockWhitelist { public List<Address> getAddresses() { return new ArrayList<>(whitelistedAddresses.keySet()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
@Test public void isWhitelisted() { for (Address address : addresses.keySet()) { assertExistance(address, true); } Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3PLxDiwWqa5uH7fSbHCxS6VAjD9Y7Rwkj" ); assertExistance(randomAddress, false); }
public boolean isWhitelisted(Address address) { return whitelistedAddresses.containsKey(address); }
LockWhitelist { public boolean isWhitelisted(Address address) { return whitelistedAddresses.containsKey(address); } }
LockWhitelist { public boolean isWhitelisted(Address address) { return whitelistedAddresses.containsKey(address); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
LockWhitelist { public boolean isWhitelisted(Address address) { return whitelistedAddresses.containsKey(address); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
LockWhitelist { public boolean isWhitelisted(Address address) { return whitelistedAddresses.containsKey(address); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
@Test public void addOneOff() { Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3WzdjG7S2GjDbY1pJYxsY1VSQDkm4KDcm" ); assertExistance(randomAddress, false); Assert.assertTrue(whitelist.put(randomAddress, new OneOffWhiteListEntry(randomAddress, Coin.CENT))); assertExistance(randomAddress, true); Assert.assertFalse(whitelist.put(randomAddress, new OneOffWhiteListEntry(randomAddress, Coin.CENT))); }
public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
@Test public void addUnlimited() { Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3WzdjG7S2GjDbY1pJYxsY1VSQDkm4KDcm" ); assertExistance(randomAddress, false); Assert.assertTrue(whitelist.put(randomAddress, new UnlimitedWhiteListEntry(randomAddress))); assertExistance(randomAddress, true); Assert.assertFalse(whitelist.put(randomAddress, new UnlimitedWhiteListEntry(randomAddress))); }
public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
@Test public void addOneOffAfterUnlimited() { Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3WzdjG7S2GjDbY1pJYxsY1VSQDkm4KDcm" ); assertExistance(randomAddress, false); Assert.assertTrue(whitelist.put(randomAddress, new UnlimitedWhiteListEntry(randomAddress))); assertExistance(randomAddress, true); Assert.assertFalse(whitelist.put(randomAddress, new OneOffWhiteListEntry(randomAddress, Coin.CENT))); }
public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
LockWhitelist { public boolean put(Address address, LockWhitelistEntry entry) { if (whitelistedAddresses.containsKey(address)) { return false; } whitelistedAddresses.put(address, entry); return true; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }