method2testcases
stringlengths
118
3.08k
### Question: PlaylistSubscriberStream extends AbstractClientStream implements IPlaylistSubscriberStream, IPlaylistSubscriberStreamStatistics { public void close() { engine.close(); bwController.unregisterBWControllable(bwContext); notifySubscriberClose(); } PlaylistSubscriberStream(); void setExecutor(ScheduledThreadPoolExecutor executor); ScheduledThreadPoolExecutor getExecutor(); void setBufferCheckInterval(int bufferCheckInterval); void setUnderrunTrigger(int underrunTrigger); void start(); void play(); void pause(int position); void resume(int position); void stop(); void seek(int position); void close(); boolean isPaused(); void addItem(IPlayItem item); void addItem(IPlayItem item, int index); void removeItem(int index); void removeAllItems(); void previousItem(); boolean hasMoreItems(); void nextItem(); void setItem(int index); boolean isRandom(); void setRandom(boolean random); boolean isRewind(); void setRewind(boolean rewind); boolean isRepeat(); void setRepeat(boolean repeat); void receiveVideo(boolean receive); void receiveAudio(boolean receive); void setPlaylistController(IPlaylistController controller); int getItemSize(); int getCurrentItemIndex(); IPlayItem getCurrentItem(); IPlayItem getItem(int index); void setBandwidthController(IBWControlService bwController); @Override void setBandwidthConfigure(IBandwidthConfigure config); void written(Object message); IPlaylistSubscriberStreamStatistics getStatistics(); long getCreationTime(); int getCurrentTimestamp(); long getBytesSent(); double getEstimatedBufferFill(); }### Answer: @Test public void testClose() { System.out.println("testClose"); pss.close(); }
### Question: ExtendedPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer { public Properties getMergedProperties() { return mergedProperties; } Properties getMergedProperties(); void setWildcardLocations( String[] locations ); static synchronized void addGlobalProperty( String key, String val ); }### Answer: @Test public void testLocationsProperty() { ExtendedPropertyPlaceholderConfigurer configurer = (ExtendedPropertyPlaceholderConfigurer)context.getBean( "boringPlaceholderConfig" ); assertEquals( testProperties, configurer.getMergedProperties() ); } @Test public void testWildcardLocationsProperty() { ExtendedPropertyPlaceholderConfigurer configurer = (ExtendedPropertyPlaceholderConfigurer)context.getBean( "wildcard1PlaceholderConfig" ); Properties mergedProp = new Properties(); mergedProp.putAll( testProperties ); mergedProp.putAll( testAProperties ); mergedProp.putAll( testBProperties ); assertEquals( mergedProp, configurer.getMergedProperties() ); configurer = (ExtendedPropertyPlaceholderConfigurer)context.getBean( "wildcard2PlaceholderConfig" ); mergedProp = new Properties(); mergedProp.putAll( testAProperties ); mergedProp.putAll( testBProperties ); mergedProp.putAll( testProperties ); assertEquals( mergedProp, configurer.getMergedProperties() ); } @Test public void testLocationsPropertyOverridesWildcardLocationsProperty() { ExtendedPropertyPlaceholderConfigurer configurer = (ExtendedPropertyPlaceholderConfigurer)context.getBean( "locationsOverridesWildcardLocationsPlaceholderConfig" ); Properties mergedProp = new Properties(); mergedProp.putAll( testProperties ); assertEquals( mergedProp, configurer.getMergedProperties() ); }
### Question: HMAC { public byte[] computeMac() { Mac hm = null; byte[] result = null; if (log.isDebugEnabled()) { log.debug("Key data: {}", byteArrayToHex(keyBytes)); log.debug("Hash data: {}", byteArrayToHex(dataBytes)); log.debug("Algorithm: {}", ALGORITHM_ID); } try { hm = Mac.getInstance(ALGORITHM_ID); Key k1 = new SecretKeySpec(keyBytes, 0, keyBytes.length, ALGORITHM_ID); hm.init(k1); result = hm.doFinal(dataBytes); } catch (Exception e) { log.warn("Bad algorithm or crypto library problem", e); } return result; } static final boolean isHexStringChar(char c); static final boolean isHex(String sampleData); static final boolean isHex(byte[] sampleData, int len); static final byte[] hexToByteArray(String str, boolean rev); static final String byteArrayToHex(byte[] a); byte[] readDataFile(File f, int minValidLength); byte[] readDataStream(InputStream is, int minValidLength); byte[] computeMac(); static final String ALGORITHM_ID; static final int MIN_LENGTH; static final int BUF_LENGTH; }### Answer: @Test public void testHMAC() { HMAC h1 = new HMAC(); assertNotNull(h1); try { Provider sp = new com.sun.crypto.provider.SunJCE(); Security.addProvider(sp); } catch (Exception e) { fail("Problem loading crypto provider" + e); } byte[] hmac = h1.computeMac(); assertNull("Currently HMAC is broken since you can't actually " + "set the keyData or data elements. This test will break once someone fixes that", hmac); }
### Question: JMXFactory { public static ObjectName createMBean(String className, String attributes) { log.info("Create the {} MBean within the MBeanServer", className); ObjectName objectName = null; try { StringBuilder objectNameStr = new StringBuilder(domain); objectNameStr.append(":type="); objectNameStr.append(className .substring(className.lastIndexOf(".") + 1)); objectNameStr.append(","); objectNameStr.append(attributes); log.info("ObjectName = {}", objectNameStr); objectName = new ObjectName(objectNameStr.toString()); if (!mbs.isRegistered(objectName)) { mbs.createMBean(className, objectName); } else { log.debug("MBean has already been created: {}", objectName); } } catch (Exception e) { log.error("Could not create the {} MBean. {}", className, e); } return objectName; } static ObjectName createMBean(String className, String attributes); static ObjectName createObjectName(String... strings); static ObjectName createSimpleMBean(String className, String objectNameStr); static String getDefaultDomain(); static MBeanServer getMBeanServer(); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass, ObjectName name); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass, String name); String getDomain(); void setDomain(String domain); }### Answer: @Test public void testCreateMBean() { ObjectName objectName = null; try { objectName = JMXFactory.createMBean( "org.red5.server.jmx.JMXFactoryTest", "test=1"); assertNotNull(objectName); objectName = JMXFactory.createMBean( "org.red5.server.jmx.JMXFactoryTest", "test=2"); assertNotNull(objectName); objectName = JMXFactory.createMBean( "org.red5.server.jmx.JMXFactoryTest", "test=1"); assertNotNull(objectName); } catch (Exception e) { fail("Exception occured"); } }
### Question: JMXFactory { public static ObjectName createSimpleMBean(String className, String objectNameStr) { log.info("Create the {} MBean within the MBeanServer", className); log.info("ObjectName = {}", objectNameStr); try { ObjectName objectName = ObjectName.getInstance(objectNameStr); if (!mbs.isRegistered(objectName)) { mbs.createMBean(className, objectName); } else { log.debug("MBean has already been created: {}", objectName); } return objectName; } catch (Exception e) { log.error("Could not create the {} MBean. {}", className, e); } return null; } static ObjectName createMBean(String className, String attributes); static ObjectName createObjectName(String... strings); static ObjectName createSimpleMBean(String className, String objectNameStr); static String getDefaultDomain(); static MBeanServer getMBeanServer(); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass, ObjectName name); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass, String name); String getDomain(); void setDomain(String domain); }### Answer: @Test public void testCreateSimpleMBean() { System.out.println("Not yet implemented"); }
### Question: JMXFactory { public static String getDefaultDomain() { return domain; } static ObjectName createMBean(String className, String attributes); static ObjectName createObjectName(String... strings); static ObjectName createSimpleMBean(String className, String objectNameStr); static String getDefaultDomain(); static MBeanServer getMBeanServer(); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass, ObjectName name); @SuppressWarnings("unchecked") static boolean registerNewMBean(String className, Class interfaceClass, String name); String getDomain(); void setDomain(String domain); }### Answer: @Test public void testGetDefaultDomain() { System.out.println("Not yet implemented"); }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { public static PhysicsUnit<?> valueOf(CharSequence charSequence) { return UCUMFormat.getCaseSensitiveInstance().parse(charSequence, new ParsePosition(0)); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testValueOf() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<?> alternate(String symbol) { return new AlternateUnit(this, symbol); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testAlternate() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<Q> transform(UnitConverter operation) { PhysicsUnit<Q> systemUnit = this.getSystemUnit(); UnitConverter cvtr = this.getConverterToSI().concatenate(operation); if (cvtr.equals(PhysicsConverter.IDENTITY)) return systemUnit; return new TransformedUnit<Q>(systemUnit, cvtr); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testTransform() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<Q> add(double offset) { if (offset == 0) return this; return transform(new AddConverter(offset)); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testAdd() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<?> inverse() { if (this.equals(SI.ONE)) return this; return ProductUnit.getQuotientInstance(SI.ONE, this); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testInverse() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<?> root(int n) { if (n > 0) return ProductUnit.getRootInstance(this, n); else if (n == 0) throw new ArithmeticException("Root's order of zero"); else return SI.ONE.divide(this.root(-n)); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testRoot() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<?> pow(int n) { if (n > 0) return this.multiply(this.pow(n - 1)); else if (n == 0) return SI.ONE; else return SI.ONE.divide(this.pow(-n)); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testPow() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public abstract int hashCode(); protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testHashCode() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public abstract boolean equals(Object that); protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testEquals() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { public AnnotatedUnit<Q> annotate(String annotation) { return new AnnotatedUnit<Q>(this, annotation); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testAnnotate() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public String toString() { TextBuilder tmp = TextBuilder.newInstance(); try { return UCUMFormat.getCaseSensitiveInstance().format(this, tmp).toString(); } catch (IOException ioException) { throw new Error(ioException); } finally { TextBuilder.recycle(tmp); } } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testToString() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public String getSymbol() { return null; } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testGetSymbol() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final PhysicsUnit<Q> getSystemUnit() { return toSI(); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testGetSystemUnit() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testGetProductUnits() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public abstract PhysicsDimension getDimension(); protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testGetDimension() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final boolean isCompatible(Unit<?> that) { if ((this == that) || this.equals(that)) return true; if (!(that instanceof PhysicsUnit)) return false; PhysicsDimension thisDimension = this.getDimension(); PhysicsDimension thatDimension = ((PhysicsUnit)that).getDimension(); if (thisDimension.equals(thatDimension)) return true; DimensionalModel model = DimensionalModel.getCurrent(); return model.getFundamentalDimension(thisDimension).equals(model.getFundamentalDimension(thatDimension)); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testIsCompatible() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final <T extends Quantity<T>> PhysicsUnit<T> asType(Class<T> type) { PhysicsDimension typeDimension = PhysicsDimension.getDimension(type); if ((typeDimension != null) && (!this.getDimension().equals(typeDimension))) throw new ClassCastException("The unit: " + this + " is not compatible with quantities of type " + type); return (PhysicsUnit<T>) this; } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testAsType() { }
### Question: PhysicsUnit implements Unit<Q>, XMLSerializable { @Override public final UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException { if ((this == that) || this.equals(that)) return PhysicsConverter.IDENTITY; Unit<Q> thisSystemUnit = this.getSystemUnit(); Unit<Q> thatSystemUnit = that.getSystemUnit(); if (!thisSystemUnit.equals(thatSystemUnit)) return getConverterToAny(that); UnitConverter thisToSI= this.getConverterToSI(); UnitConverter thatToSI= that.getConverterTo(thatSystemUnit); return thatToSI.inverse().concatenate(thisToSI); } protected PhysicsUnit(); boolean isSI(); abstract PhysicsUnit<Q> toSI(); abstract UnitConverter getConverterToSI(); AnnotatedUnit<Q> annotate(String annotation); static PhysicsUnit<?> valueOf(CharSequence charSequence); @Override String toString(); @Override final PhysicsUnit<Q> getSystemUnit(); @Override final boolean isCompatible(Unit<?> that); @Override final PhysicsUnit<T> asType(Class<T> type); @Override String getSymbol(); @Override abstract Map<? extends PhysicsUnit, Integer> getProductUnits(); @Override abstract PhysicsDimension getDimension(); @Override final UnitConverter getConverterTo(Unit<Q> that); @Override final UnitConverter getConverterToAny(Unit<?> that); @Override final PhysicsUnit<?> alternate(String symbol); @Override final PhysicsUnit<Q> transform(UnitConverter operation); @Override final PhysicsUnit<Q> add(double offset); @Override final PhysicsUnit<Q> multiply(double factor); @Override final Unit<?> multiply(Unit<?> that); final PhysicsUnit<?> multiply(PhysicsUnit<?> that); @Override final PhysicsUnit<?> inverse(); @Override final PhysicsUnit<Q> divide(double divisor); @Override final Unit<?> divide(Unit<?> that); final PhysicsUnit<?> divide(PhysicsUnit<?> that); @Override final PhysicsUnit<?> root(int n); @Override final PhysicsUnit<?> pow(int n); @Override abstract int hashCode(); @Override abstract boolean equals(Object that); }### Answer: @Test public void testGetConverterTo() { }
### Question: RawCopier { public static <T> RawCopier<T> copies(Class<T> tClass) { return new RawCopier<T>(tClass); } private RawCopier(Class<T> tClass); static RawCopier<T> copies(Class<T> tClass); int start(); int end(); void toBytes(Object obj, Bytes bytes); void fromBytes(Bytes bytes, Object obj); void copy(T from, T to); }### Answer: @Test public void testStartEnd() { RawCopier<A> aRawCopier = RawCopier.copies(A.class); if (aRawCopier.start != 8) assertEquals(12, aRawCopier.start); assertEquals(aRawCopier.start + 3 * 4, aRawCopier.end); RawCopier<B> bRawCopier = RawCopier.copies(B.class); if (aRawCopier.start != 8) assertEquals(16, bRawCopier.start); assertEquals(bRawCopier.start + 4 * 8, bRawCopier.end); }
### Question: ResizeableMappedStore extends AbstractMappedStore { public void resize(long newSize) throws IOException { validateSize(newSize); unmapAndSyncToDisk(); resizeIfNeeded(0L, newSize); this.mmapInfoHolder.setSize(newSize); map(0L); } ResizeableMappedStore(File file, FileChannel.MapMode mode, long size); ResizeableMappedStore(File file, FileChannel.MapMode mode, long size, ObjectSerializer objectSerializer); void resize(long newSize); }### Answer: @Test public void testResizableMappedStore() throws IOException { File file = MappedStoreTest.getStoreFile("resizable-mapped-store.tmp"); final int smallSize = 1024, largeSize = 10 * smallSize; { ResizeableMappedStore ms = new ResizeableMappedStore(file, FileChannel.MapMode.READ_WRITE, smallSize); DirectBytes slice1 = ms.bytes(); for (int i = 0; i < smallSize; ++i) { slice1.writeByte(42); } ms.resize(largeSize); DirectBytes slice2 = ms.bytes(); slice2.skipBytes(smallSize); for (int i = smallSize; i < largeSize; ++i) { slice2.writeByte(24); } ms.close(); } assertEquals(largeSize, file.length()); { ResizeableMappedStore ms = new ResizeableMappedStore(file, FileChannel.MapMode.READ_WRITE, file.length()); DirectBytes slice = ms.bytes(); assertEquals(42, slice.readByte(smallSize - 1)); assertEquals(24, slice.readByte(largeSize - 1)); slice.release(); ms.close(); } }
### Question: LightPauser implements Pauser { public LightPauser(long busyPeriodNS, long parkPeriodNS) { this.busyPeriodNS = busyPeriodNS; this.parkPeriodNS = parkPeriodNS; } LightPauser(long busyPeriodNS, long parkPeriodNS); @Override void reset(); @Override void pause(); void pause(long maxPauseNS); @Override void unpause(); static final long NO_BUSY_PERIOD; static final long NO_PAUSE_PERIOD; }### Answer: @Test public void testLightPauser() throws InterruptedException { final LightPauser pauser = new LightPauser(100 * 1000, 100 * 1000); Thread thread = new Thread() { @Override public void run() { while (!Thread.interrupted()) pauser.pause(); } }; thread.start(); for (int t = 0; t < 3; t++) { long start = System.nanoTime(); int runs = 10000000; for (int i = 0; i < runs; i++) pauser.unpause(); long time = System.nanoTime() - start; System.out.printf("Average time to unpark was %,d ns%n", time / runs); Thread.sleep(20); } thread.interrupt(); }
### Question: Maths { public static int intLog2(long num) { long l = Double.doubleToRawLongBits(num); return (int) ((l >> 52) - 1023); } static double round2(double d); static double round4(double d); static double round6(double d); static double round8(double d); static long power10(int n); static int nextPower2(int n, int min); static long nextPower2(long n, long min); static boolean isPowerOf2(int n); static boolean isPowerOf2(long n); static int hash(int n); static long hash(long n); static long hash(CharSequence cs); static int compare(long x, long y); static int intLog2(long num); static int toInt(long l, String error); static long agitate(long l); }### Answer: @Test public void testIntLog2() { for (int i = 0; i < 63; i++) { long l = 1L << i; assertEquals(i, Maths.intLog2(l)); } }
### Question: HelloWorldController { @RequestMapping("/") public String sayHello() { return "Hello,World!"; } @RequestMapping("/") String sayHello(); @PostMapping(value = "/request_param") String requestParam(@RequestParam(value = "name") String name); @PostMapping(value = "/request_body") UserInfo requestBody(@RequestParam(value = "name") String name, @RequestBody UserInfo info); @PostMapping(value = "/request_body1") UserInfo requestBody1(@RequestBody UserInfo info); }### Answer: @Test public void testSayHello() { assertEquals("Hello,World!",new HelloWorldController().sayHello()); }
### Question: OpenhabSseConnection extends SseConnection implements SseConnection.ISseDataListener { @Override protected String buildUrl() { return mUrl + "/rest/events?topics=" + buildTopic(); } OpenhabSseConnection(); void removeItemValueListener(IStateUpdateListener l); @Override void data(String data); }### Answer: @Test public void testBuildUrl() { OpenhabSseConnection c = new OpenhabSseConnection(); c.setServerUrl("URL"); c.setItemNames("cmdName"); assertEquals("URL/rest/events?topics=smarthome/items/cmdName/command", c.buildUrl()); c.setItemNames("cmdName","item1", "item2"); assertEquals("URL/rest/events?topics=smarthome/items/item1/statechanged,smarthome/items/item2/statechanged,smarthome/items/cmdName/command", c.buildUrl()); }
### Question: LocalizedFieldNames { public Lookup createLookup(List<String> keys) { return new LookupImpl(keys); } void setMessageSource(MessageSource messageSource); Lookup createLookup(List<String> keys); }### Answer: @Test public void backAndForth() { LocalizedFieldNames.Lookup lookup = localizedFieldNames.createLookup(Arrays.asList("dc.title")); final Locale english = new Locale("en"); String title = lookup.toLocalizedName("dc_title", english); Assert.assertEquals("Title", title); String fieldName = lookup.toFieldName(title, english); Assert.assertEquals("dc_title", fieldName); } @Test public void multiWord() { LocalizedFieldNames.Lookup lookup = localizedFieldNames.createLookup(Arrays.asList("dcterms.isReferencedBy")); final Locale english = new Locale("en"); String fieldName = lookup.toFieldName("isreferENCedby", english); Assert.assertEquals("dcterms_isReferencedBy", fieldName); }
### Question: BordersExtractor { public boolean isBorder(int edgeId) { int type = storage.getEdgeValue(edgeId, BordersGraphStorage.Property.TYPE); return (type == BordersGraphStorage.OPEN_BORDER || type == BordersGraphStorage.CONTROLLED_BORDER); } BordersExtractor(BordersGraphStorage storage, int[] avoidCountries); int getValue(int edgeId); boolean isBorder(int edgeId); boolean isControlledBorder(int edgeId); boolean isOpenBorder(int edgeId); boolean restrictedCountry(int edgeId); boolean isSameCountry(List<Integer> edgeIds); }### Answer: @Test public void TestDetectAnyBorder() { VirtualEdgeIteratorState ve1 = generateEdge(1); VirtualEdgeIteratorState ve2 = generateEdge(2); VirtualEdgeIteratorState ve3 = generateEdge(3); BordersExtractor be = new BordersExtractor(_graphstorage, new int[0]); assertEquals(true, be.isBorder(1)); assertEquals(true, be.isBorder(2)); assertEquals(false, be.isBorder(3)); }
### Question: IsochronesResponse { public BoundingBox getBbox() { return bbox; } IsochronesResponse(IsochronesRequest request); IsochronesResponseInfo getResponseInformation(); BoundingBox getBbox(); }### Answer: @Test public void getBbox() { }
### Question: GeoJSONIsochronesResponse extends IsochronesResponse { @JsonProperty("features") public List<GeoJSONIsochroneBase> getIsochrones() { return isochroneResults; } GeoJSONIsochronesResponse(IsochronesRequest request, IsochroneMapCollection isoMaps); @JsonProperty("bbox") @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModelProperty(value = "Bounding box that covers all returned isochrones", example = "[49.414057, 8.680894, 49.420514, 8.690123]") double[] getBBoxAsArray(); @JsonProperty("features") List<GeoJSONIsochroneBase> getIsochrones(); @JsonProperty("metadata") IsochronesResponseInfo getProperties(); @JsonProperty("type") final String type; }### Answer: @Test public void getIsochrones() { }
### Question: GeoJSONIsochronesResponse extends IsochronesResponse { @JsonProperty("metadata") public IsochronesResponseInfo getProperties() { return this.responseInformation; } GeoJSONIsochronesResponse(IsochronesRequest request, IsochroneMapCollection isoMaps); @JsonProperty("bbox") @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModelProperty(value = "Bounding box that covers all returned isochrones", example = "[49.414057, 8.680894, 49.420514, 8.690123]") double[] getBBoxAsArray(); @JsonProperty("features") List<GeoJSONIsochroneBase> getIsochrones(); @JsonProperty("metadata") IsochronesResponseInfo getProperties(); @JsonProperty("type") final String type; }### Answer: @Test public void getProperties() { }
### Question: GeoJSONIsochroneProperties { public Double getValue() { return value; } GeoJSONIsochroneProperties(Isochrone isochrone, Coordinate center, int groupIndex); int getGroupIndex(); Double getValue(); Double[] getCenter(); Double getArea(); Double getReachfactor(); Double getTotalPop(); }### Answer: @Test public void getValue() { }
### Question: GeoJSONIsochroneProperties { public Double[] getCenter() { return center; } GeoJSONIsochroneProperties(Isochrone isochrone, Coordinate center, int groupIndex); int getGroupIndex(); Double getValue(); Double[] getCenter(); Double getArea(); Double getReachfactor(); Double getTotalPop(); }### Answer: @Test public void getCenter() { }
### Question: GeoJSONIsochroneProperties { public Double getArea() { return area; } GeoJSONIsochroneProperties(Isochrone isochrone, Coordinate center, int groupIndex); int getGroupIndex(); Double getValue(); Double[] getCenter(); Double getArea(); Double getReachfactor(); Double getTotalPop(); }### Answer: @Test public void getArea() { }
### Question: GeoJSONIsochroneProperties { public Double getReachfactor() { return reachfactor; } GeoJSONIsochroneProperties(Isochrone isochrone, Coordinate center, int groupIndex); int getGroupIndex(); Double getValue(); Double[] getCenter(); Double getArea(); Double getReachfactor(); Double getTotalPop(); }### Answer: @Test public void getReachfactor() { }
### Question: MatrixRequestHandler { public static int convertMetrics(MatrixRequestEnums.Metrics[] metrics) throws ParameterValueException { List<String> metricsAsStrings = new ArrayList<>(); for (int i=0; i<metrics.length; i++) { metricsAsStrings.add(metrics[i].toString()); } String concatMetrics = String.join("|", metricsAsStrings); int combined = MatrixMetricsType.getFromString(concatMetrics); if (combined == MatrixMetricsType.UNKNOWN) throw new ParameterValueException(MatrixErrorCodes.INVALID_PARAMETER_VALUE, MatrixRequest.PARAM_METRICS); return combined; } private MatrixRequestHandler(); static MatrixResult generateMatrixFromRequest(MatrixRequest request); static org.heigit.ors.matrix.MatrixRequest convertMatrixRequest(MatrixRequest request); static int convertMetrics(MatrixRequestEnums.Metrics[] metrics); }### Answer: @Test public void convertMetricsTest() throws ParameterValueException { Assert.assertEquals(1, MatrixRequestHandler.convertMetrics(new MatrixRequestEnums.Metrics[] {MatrixRequestEnums.Metrics.DURATION})); Assert.assertEquals(2, MatrixRequestHandler.convertMetrics(new MatrixRequestEnums.Metrics[] {MatrixRequestEnums.Metrics.DISTANCE})); Assert.assertEquals(3, MatrixRequestHandler.convertMetrics(new MatrixRequestEnums.Metrics[] {MatrixRequestEnums.Metrics.DURATION, MatrixRequestEnums.Metrics.DISTANCE})); }
### Question: MatrixRequestHandler { protected static Coordinate convertSingleLocationCoordinate(List<Double> coordinate) throws ParameterValueException { if (coordinate.size() != 2) throw new ParameterValueException(MatrixErrorCodes.INVALID_PARAMETER_VALUE, MatrixRequest.PARAM_LOCATIONS); return new Coordinate(coordinate.get(0), coordinate.get(1)); } private MatrixRequestHandler(); static MatrixResult generateMatrixFromRequest(MatrixRequest request); static org.heigit.ors.matrix.MatrixRequest convertMatrixRequest(MatrixRequest request); static int convertMetrics(MatrixRequestEnums.Metrics[] metrics); }### Answer: @Test public void convertSingleLocationCoordinateTest() throws ParameterValueException { List<Double> locationsList = new ArrayList<>(); locationsList.add(8.681495); locationsList.add(49.41461); Coordinate coordinates = MatrixRequestHandler.convertSingleLocationCoordinate(locationsList); Assert.assertEquals(8.681495, coordinates.x, 0); Assert.assertEquals(49.41461, coordinates.y, 0); Assert.assertEquals(Double.NaN, coordinates.z, 0); } @Test(expected = ParameterValueException.class) public void convertWrongSingleLocationCoordinateTest() throws ParameterValueException { List<Double> locationsList = new ArrayList<>(); locationsList.add(8.681495); locationsList.add(49.41461); locationsList.add(123.0); MatrixRequestHandler.convertSingleLocationCoordinate(locationsList); }
### Question: MatrixRequestHandler { protected static ArrayList<Coordinate> convertIndexToLocations(String[] index, Coordinate[] locations) { ArrayList<Coordinate> indexCoordinates = new ArrayList<>(); for (String indexString : index) { int indexInteger = Integer.parseInt(indexString); indexCoordinates.add(locations[indexInteger]); } return indexCoordinates; } private MatrixRequestHandler(); static MatrixResult generateMatrixFromRequest(MatrixRequest request); static org.heigit.ors.matrix.MatrixRequest convertMatrixRequest(MatrixRequest request); static int convertMetrics(MatrixRequestEnums.Metrics[] metrics); }### Answer: @Test public void convertIndexToLocationsTest() throws Exception { ArrayList<Coordinate> coordinate = MatrixRequestHandler.convertIndexToLocations(new String[]{"1"}, this.coordinates); Assert.assertEquals(8.686507, coordinate.get(0).x, 0); Assert.assertEquals(49.41943, coordinate.get(0).y, 0); Assert.assertEquals(Double.NaN, coordinate.get(0).z, 0); } @Test(expected = Exception.class) public void convertWrongIndexToLocationsTest() throws Exception { MatrixRequestHandler.convertIndexToLocations(new String[]{"foo"}, this.coordinates); }
### Question: MatrixRequestHandler { protected static DistanceUnit convertUnits(APIEnums.Units unitsIn) throws ParameterValueException { DistanceUnit units = DistanceUnitUtil.getFromString(unitsIn.toString(), DistanceUnit.UNKNOWN); if (units == DistanceUnit.UNKNOWN) throw new ParameterValueException(MatrixErrorCodes.INVALID_PARAMETER_VALUE, MatrixRequest.PARAM_UNITS, unitsIn.toString()); return units; } private MatrixRequestHandler(); static MatrixResult generateMatrixFromRequest(MatrixRequest request); static org.heigit.ors.matrix.MatrixRequest convertMatrixRequest(MatrixRequest request); static int convertMetrics(MatrixRequestEnums.Metrics[] metrics); }### Answer: @Test public void convertUnitsTest() throws ParameterValueException { Assert.assertEquals(DistanceUnit.METERS, MatrixRequestHandler.convertUnits(APIEnums.Units.METRES)); Assert.assertEquals(DistanceUnit.KILOMETERS, MatrixRequestHandler.convertUnits(APIEnums.Units.KILOMETRES)); Assert.assertEquals(DistanceUnit.MILES, MatrixRequestHandler.convertUnits(APIEnums.Units.MILES)); }
### Question: MatrixRequest { public String getId() { return id; } @JsonCreator MatrixRequest(@JsonProperty(value = "locations", required = true) List<List<Double>> locations); MatrixRequest(Double[][] locations); String getId(); void setId(String id); boolean hasId(); APIEnums.Profile getProfile(); void setProfile(APIEnums.Profile profile); List<List<Double>> getLocations(); void setLocations(List<List<Double>> locations); String[] getSources(); void setSources(String[] sources); boolean hasSources(); String[] getDestinations(); void setDestinations(String[] destinations); boolean hasDestinations(); MatrixRequestEnums.Metrics[] getMetrics(); Set<String> getMetricsStrings(); void setMetrics(MatrixRequestEnums.Metrics[] metrics); boolean hasMetrics(); boolean getResolveLocations(); void setResolveLocations(boolean resolveLocations); boolean hasResolveLocations(); APIEnums.Units getUnits(); void setUnits(APIEnums.Units units); boolean hasUnits(); Boolean getOptimized(); void setOptimized(boolean optimized); boolean hasOptimized(); APIEnums.MatrixResponseType getResponseType(); void setResponseType(APIEnums.MatrixResponseType responseType); static final String PARAM_ID; static final String PARAM_PROFILE; static final String PARAM_LOCATIONS; static final String PARAM_SOURCES; static final String PARAM_DESTINATIONS; static final String PARAM_METRICS; static final String PARAM_RESOLVE_LOCATIONS; static final String PARAM_UNITS; static final String PARAM_OPTIMIZED; }### Answer: @Test public void getIdTest() throws ParameterValueException { matrixLocationsRequest = new MatrixRequest(bareCoordinates); matrixLocationsListRequest = new MatrixRequest(listOfBareCoordinatesList); Assert.assertNull(matrixLocationsRequest.getId()); Assert.assertNull(matrixLocationsListRequest.getId()); }
### Question: MatrixRequest { public void setId(String id) { this.id = id; } @JsonCreator MatrixRequest(@JsonProperty(value = "locations", required = true) List<List<Double>> locations); MatrixRequest(Double[][] locations); String getId(); void setId(String id); boolean hasId(); APIEnums.Profile getProfile(); void setProfile(APIEnums.Profile profile); List<List<Double>> getLocations(); void setLocations(List<List<Double>> locations); String[] getSources(); void setSources(String[] sources); boolean hasSources(); String[] getDestinations(); void setDestinations(String[] destinations); boolean hasDestinations(); MatrixRequestEnums.Metrics[] getMetrics(); Set<String> getMetricsStrings(); void setMetrics(MatrixRequestEnums.Metrics[] metrics); boolean hasMetrics(); boolean getResolveLocations(); void setResolveLocations(boolean resolveLocations); boolean hasResolveLocations(); APIEnums.Units getUnits(); void setUnits(APIEnums.Units units); boolean hasUnits(); Boolean getOptimized(); void setOptimized(boolean optimized); boolean hasOptimized(); APIEnums.MatrixResponseType getResponseType(); void setResponseType(APIEnums.MatrixResponseType responseType); static final String PARAM_ID; static final String PARAM_PROFILE; static final String PARAM_LOCATIONS; static final String PARAM_SOURCES; static final String PARAM_DESTINATIONS; static final String PARAM_METRICS; static final String PARAM_RESOLVE_LOCATIONS; static final String PARAM_UNITS; static final String PARAM_OPTIMIZED; }### Answer: @Test public void setIdTest() throws ParameterValueException { matrixLocationsRequest = new MatrixRequest(bareCoordinates); matrixLocationsListRequest = new MatrixRequest(listOfBareCoordinatesList); matrixLocationsRequest.setId("foo1"); matrixLocationsListRequest.setId("foo2"); Assert.assertEquals("foo1", matrixLocationsRequest.getId()); Assert.assertEquals("foo2", matrixLocationsListRequest.getId()); }
### Question: MatrixRequest { public boolean hasId() { return this.id != null; } @JsonCreator MatrixRequest(@JsonProperty(value = "locations", required = true) List<List<Double>> locations); MatrixRequest(Double[][] locations); String getId(); void setId(String id); boolean hasId(); APIEnums.Profile getProfile(); void setProfile(APIEnums.Profile profile); List<List<Double>> getLocations(); void setLocations(List<List<Double>> locations); String[] getSources(); void setSources(String[] sources); boolean hasSources(); String[] getDestinations(); void setDestinations(String[] destinations); boolean hasDestinations(); MatrixRequestEnums.Metrics[] getMetrics(); Set<String> getMetricsStrings(); void setMetrics(MatrixRequestEnums.Metrics[] metrics); boolean hasMetrics(); boolean getResolveLocations(); void setResolveLocations(boolean resolveLocations); boolean hasResolveLocations(); APIEnums.Units getUnits(); void setUnits(APIEnums.Units units); boolean hasUnits(); Boolean getOptimized(); void setOptimized(boolean optimized); boolean hasOptimized(); APIEnums.MatrixResponseType getResponseType(); void setResponseType(APIEnums.MatrixResponseType responseType); static final String PARAM_ID; static final String PARAM_PROFILE; static final String PARAM_LOCATIONS; static final String PARAM_SOURCES; static final String PARAM_DESTINATIONS; static final String PARAM_METRICS; static final String PARAM_RESOLVE_LOCATIONS; static final String PARAM_UNITS; static final String PARAM_OPTIMIZED; }### Answer: @Test public void hasIdTest() throws ParameterValueException { matrixLocationsRequest = new MatrixRequest(bareCoordinates); matrixLocationsListRequest = new MatrixRequest(listOfBareCoordinatesList); Assert.assertFalse(matrixLocationsRequest.hasId()); Assert.assertFalse(matrixLocationsListRequest.hasId()); matrixLocationsRequest.setId("foo1"); matrixLocationsListRequest.setId("foo2"); Assert.assertTrue(matrixLocationsRequest.hasId()); Assert.assertTrue(matrixLocationsListRequest.hasId()); }
### Question: MatrixRequest { public APIEnums.Profile getProfile() { return profile; } @JsonCreator MatrixRequest(@JsonProperty(value = "locations", required = true) List<List<Double>> locations); MatrixRequest(Double[][] locations); String getId(); void setId(String id); boolean hasId(); APIEnums.Profile getProfile(); void setProfile(APIEnums.Profile profile); List<List<Double>> getLocations(); void setLocations(List<List<Double>> locations); String[] getSources(); void setSources(String[] sources); boolean hasSources(); String[] getDestinations(); void setDestinations(String[] destinations); boolean hasDestinations(); MatrixRequestEnums.Metrics[] getMetrics(); Set<String> getMetricsStrings(); void setMetrics(MatrixRequestEnums.Metrics[] metrics); boolean hasMetrics(); boolean getResolveLocations(); void setResolveLocations(boolean resolveLocations); boolean hasResolveLocations(); APIEnums.Units getUnits(); void setUnits(APIEnums.Units units); boolean hasUnits(); Boolean getOptimized(); void setOptimized(boolean optimized); boolean hasOptimized(); APIEnums.MatrixResponseType getResponseType(); void setResponseType(APIEnums.MatrixResponseType responseType); static final String PARAM_ID; static final String PARAM_PROFILE; static final String PARAM_LOCATIONS; static final String PARAM_SOURCES; static final String PARAM_DESTINATIONS; static final String PARAM_METRICS; static final String PARAM_RESOLVE_LOCATIONS; static final String PARAM_UNITS; static final String PARAM_OPTIMIZED; }### Answer: @Test public void getProfileTest() throws ParameterValueException { matrixLocationsRequest = new MatrixRequest(bareCoordinates); matrixLocationsListRequest = new MatrixRequest(listOfBareCoordinatesList); Assert.assertNull(matrixLocationsRequest.getProfile()); Assert.assertNull(matrixLocationsListRequest.getProfile()); }
### Question: MatrixRequest { public List<List<Double>> getLocations() { return locations; } @JsonCreator MatrixRequest(@JsonProperty(value = "locations", required = true) List<List<Double>> locations); MatrixRequest(Double[][] locations); String getId(); void setId(String id); boolean hasId(); APIEnums.Profile getProfile(); void setProfile(APIEnums.Profile profile); List<List<Double>> getLocations(); void setLocations(List<List<Double>> locations); String[] getSources(); void setSources(String[] sources); boolean hasSources(); String[] getDestinations(); void setDestinations(String[] destinations); boolean hasDestinations(); MatrixRequestEnums.Metrics[] getMetrics(); Set<String> getMetricsStrings(); void setMetrics(MatrixRequestEnums.Metrics[] metrics); boolean hasMetrics(); boolean getResolveLocations(); void setResolveLocations(boolean resolveLocations); boolean hasResolveLocations(); APIEnums.Units getUnits(); void setUnits(APIEnums.Units units); boolean hasUnits(); Boolean getOptimized(); void setOptimized(boolean optimized); boolean hasOptimized(); APIEnums.MatrixResponseType getResponseType(); void setResponseType(APIEnums.MatrixResponseType responseType); static final String PARAM_ID; static final String PARAM_PROFILE; static final String PARAM_LOCATIONS; static final String PARAM_SOURCES; static final String PARAM_DESTINATIONS; static final String PARAM_METRICS; static final String PARAM_RESOLVE_LOCATIONS; static final String PARAM_UNITS; static final String PARAM_OPTIMIZED; }### Answer: @Test public void getLocationsTest() throws ParameterValueException { matrixLocationsRequest = new MatrixRequest(bareCoordinates); matrixLocationsListRequest = new MatrixRequest(listOfBareCoordinatesList); Assert.assertEquals(listOfBareCoordinatesList, matrixLocationsRequest.getLocations()); Assert.assertEquals(listOfBareCoordinatesList, matrixLocationsListRequest.getLocations()); }
### Question: MatrixRequest { public void setSources(String[] sources) { this.sources = sources; hasSources = true; } @JsonCreator MatrixRequest(@JsonProperty(value = "locations", required = true) List<List<Double>> locations); MatrixRequest(Double[][] locations); String getId(); void setId(String id); boolean hasId(); APIEnums.Profile getProfile(); void setProfile(APIEnums.Profile profile); List<List<Double>> getLocations(); void setLocations(List<List<Double>> locations); String[] getSources(); void setSources(String[] sources); boolean hasSources(); String[] getDestinations(); void setDestinations(String[] destinations); boolean hasDestinations(); MatrixRequestEnums.Metrics[] getMetrics(); Set<String> getMetricsStrings(); void setMetrics(MatrixRequestEnums.Metrics[] metrics); boolean hasMetrics(); boolean getResolveLocations(); void setResolveLocations(boolean resolveLocations); boolean hasResolveLocations(); APIEnums.Units getUnits(); void setUnits(APIEnums.Units units); boolean hasUnits(); Boolean getOptimized(); void setOptimized(boolean optimized); boolean hasOptimized(); APIEnums.MatrixResponseType getResponseType(); void setResponseType(APIEnums.MatrixResponseType responseType); static final String PARAM_ID; static final String PARAM_PROFILE; static final String PARAM_LOCATIONS; static final String PARAM_SOURCES; static final String PARAM_DESTINATIONS; static final String PARAM_METRICS; static final String PARAM_RESOLVE_LOCATIONS; static final String PARAM_UNITS; static final String PARAM_OPTIMIZED; }### Answer: @Test public void setSourcesTest() throws ParameterValueException { matrixLocationsRequest = new MatrixRequest(bareCoordinates); matrixLocationsListRequest = new MatrixRequest(listOfBareCoordinatesList); matrixLocationsRequest.setSources(new String[]{"foo"}); matrixLocationsListRequest.setSources(new String[]{"foo"}); Assert.assertArrayEquals(new String[]{"foo"}, matrixLocationsRequest.getSources()); Assert.assertArrayEquals(new String[]{"foo"}, matrixLocationsListRequest.getSources()); }
### Question: RouteRequestRoundTripOptions { public void setLength(Float length) { this.length = length; hasLength = true; } Float getLength(); void setLength(Float length); Integer getPoints(); void setPoints(Integer points); Long getSeed(); void setSeed(Long seed); boolean hasLength(); boolean hasPoints(); boolean hasSeed(); static final String PARAM_LENGTH; static final String PARAM_POINTS; static final String PARAM_SEED; }### Answer: @Test public void testSetLength() { Assert.assertFalse(options.hasLength()); options.setLength(123.4f); Assert.assertTrue(options.hasLength()); Assert.assertEquals((Float)123.4f, options.getLength()); }
### Question: RouteRequestRoundTripOptions { public void setPoints(Integer points) { this.points = points; hasPoints = true; } Float getLength(); void setLength(Float length); Integer getPoints(); void setPoints(Integer points); Long getSeed(); void setSeed(Long seed); boolean hasLength(); boolean hasPoints(); boolean hasSeed(); static final String PARAM_LENGTH; static final String PARAM_POINTS; static final String PARAM_SEED; }### Answer: @Test public void testSetPoints() { Assert.assertFalse(options.hasPoints()); options.setPoints(12); Assert.assertTrue(options.hasPoints()); Assert.assertEquals((Integer) 12, options.getPoints()); }
### Question: RouteRequestRoundTripOptions { public void setSeed(Long seed) { this.seed = seed; hasSeed = true; } Float getLength(); void setLength(Float length); Integer getPoints(); void setPoints(Integer points); Long getSeed(); void setSeed(Long seed); boolean hasLength(); boolean hasPoints(); boolean hasSeed(); static final String PARAM_LENGTH; static final String PARAM_POINTS; static final String PARAM_SEED; }### Answer: @Test public void testSetSeed() { Assert.assertFalse(options.hasSeed()); options.setSeed(1234567890l); Assert.assertTrue(options.hasSeed()); Assert.assertEquals((Long) 1234567890l, options.getSeed()); }
### Question: BordersGraphStorageBuilder extends AbstractGraphStorageBuilder { @Override public void processWay(ReaderWay way) { LOGGER.warn("Borders requires geometry for the way!"); } BordersGraphStorageBuilder(); @Override GraphExtension init(GraphHopper graphhopper); void setBordersBuilder(CountryBordersReader cbr); @Override void processWay(ReaderWay way); @Override void processWay(ReaderWay way, Coordinate[] coords, HashMap<Integer, HashMap<String,String>> nodeTags); @Override void processEdge(ReaderWay way, EdgeIteratorState edge); @Override String getName(); String[] findBorderCrossing(Coordinate[] coords); CountryBordersReader getCbReader(); static final String BUILDER_NAME; }### Answer: @Test public void TestProcessWay() { ReaderWay rw = new ReaderWay(1); Coordinate[] cs = new Coordinate[] { new Coordinate(0.5,0.5), new Coordinate(1.5,0.5) }; _builder.processWay(rw, cs, null); Assert.assertEquals("c1", rw.getTag("country1")); Assert.assertEquals("c2", rw.getTag("country2")); ReaderWay rw2 = new ReaderWay(1); Coordinate[] cs2 = new Coordinate[] { new Coordinate(0.5,0.5), new Coordinate(0.75,0.5) }; _builder.processWay(rw2, cs2, null); Assert.assertEquals("c1", rw2.getTag("country1")); Assert.assertEquals("c1", rw2.getTag("country2")); }
### Question: WheelchairSidewalkWay extends PedestrianWay { @Override public boolean hasWayBeenFullyProcessed() { if(side == OSMAttachedSidewalkProcessor.Side.BOTH && lastPrepared == OSMAttachedSidewalkProcessor.Side.RIGHT) { return true; } return side == lastPrepared; } WheelchairSidewalkWay(ReaderWay way); @Override boolean hasWayBeenFullyProcessed(); @Override void prepare(); }### Answer: @Test public void TestInitiallyProcessedIfNoSidewalk() { WheelchairSidewalkWay way = new WheelchairSidewalkWay(new ReaderWay(1)); assertTrue(way.hasWayBeenFullyProcessed()); } @Test public void TestInitiallyNotProcessedIfSidewalk() { ReaderWay readerWay = new ReaderWay(1); readerWay.setTag("sidewalk", "left"); WheelchairSidewalkWay way = new WheelchairSidewalkWay(readerWay); assertFalse(way.hasWayBeenFullyProcessed()); }
### Question: IsochronesRequestHandler extends GenericHandler { Float convertSmoothing(Double smoothingValue) throws ParameterValueException { float f = (float) smoothingValue.doubleValue(); if (smoothingValue < 0 || smoothingValue > 100) throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_SMOOTHING, smoothingValue.toString()); return f; } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertSmoothing() throws ParameterValueException { Float smoothing = handler.convertSmoothing(10.234); Assert.assertEquals(10.234, smoothing, 0.01); } @Test(expected = ParameterValueException.class) public void convertSmoothingFailWhenTooHigh() throws ParameterValueException { handler.convertSmoothing(105.0); } @Test(expected = ParameterValueException.class) public void convertSmoothingFailWhenTooLow() throws ParameterValueException { handler.convertSmoothing(-5.0); }
### Question: IsochronesRequestHandler extends GenericHandler { String convertLocationType(IsochronesRequestEnums.LocationType locationType) throws ParameterValueException { IsochronesRequestEnums.LocationType value; switch (locationType) { case DESTINATION: value = IsochronesRequestEnums.LocationType.DESTINATION; break; case START: value = IsochronesRequestEnums.LocationType.START; break; default: throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_LOCATION_TYPE, locationType.toString()); } return value.toString(); } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertLocationType() throws ParameterValueException { String locationType = handler.convertLocationType(IsochronesRequestEnums.LocationType.DESTINATION); Assert.assertEquals("destination", locationType); locationType = handler.convertLocationType(IsochronesRequestEnums.LocationType.START); Assert.assertEquals("start", locationType); }
### Question: IsochronesRequestHandler extends GenericHandler { TravelRangeType convertRangeType(IsochronesRequestEnums.RangeType rangeType) throws ParameterValueException { TravelRangeType travelRangeType; switch (rangeType) { case DISTANCE: travelRangeType = TravelRangeType.DISTANCE; break; case TIME: travelRangeType = TravelRangeType.TIME; break; default: throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_RANGE_TYPE, rangeType.toString()); } return travelRangeType; } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertRangeType() throws ParameterValueException { TravelRangeType rangeType = handler.convertRangeType(IsochronesRequestEnums.RangeType.DISTANCE); Assert.assertEquals(TravelRangeType.DISTANCE, rangeType); rangeType = handler.convertRangeType(IsochronesRequestEnums.RangeType.TIME); Assert.assertEquals(TravelRangeType.TIME, rangeType); }
### Question: IsochronesRequestHandler extends GenericHandler { String convertAreaUnit(APIEnums.Units unitsIn) throws ParameterValueException { DistanceUnit areaUnit; try { areaUnit = DistanceUnitUtil.getFromString(unitsIn.toString(), DistanceUnit.UNKNOWN); if (areaUnit == DistanceUnit.UNKNOWN) throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_AREA_UNITS, unitsIn.toString()); return DistanceUnitUtil.toString(areaUnit); } catch (Exception e) { throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_AREA_UNITS, unitsIn.toString()); } } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertAreaUnit() throws ParameterValueException { String unit = handler.convertAreaUnit(APIEnums.Units.KILOMETRES); Assert.assertEquals("km", unit); unit = handler.convertAreaUnit(APIEnums.Units.METRES); Assert.assertEquals("m", unit); unit = handler.convertAreaUnit(APIEnums.Units.MILES); Assert.assertEquals("mi", unit); }
### Question: IsochronesRequestHandler extends GenericHandler { String convertRangeUnit(APIEnums.Units unitsIn) throws ParameterValueException { DistanceUnit units; try { units = DistanceUnitUtil.getFromString(unitsIn.toString(), DistanceUnit.UNKNOWN); if (units == DistanceUnit.UNKNOWN) throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_RANGE_UNITS, unitsIn.toString()); } catch (Exception e) { throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_RANGE_UNITS, unitsIn.toString()); } return DistanceUnitUtil.toString(units); } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertRangeUnit() throws ParameterValueException { String unit = handler.convertRangeUnit(APIEnums.Units.KILOMETRES); Assert.assertEquals("km", unit); unit = handler.convertRangeUnit(APIEnums.Units.METRES); Assert.assertEquals("m", unit); unit = handler.convertRangeUnit(APIEnums.Units.MILES); Assert.assertEquals("mi", unit); }
### Question: IsochronesRequestHandler extends GenericHandler { Coordinate convertSingleCoordinate(Double[] coordinate) throws ParameterValueException { Coordinate realCoordinate; if (coordinate.length != 2) { throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_LOCATIONS); } try { realCoordinate = new Coordinate(coordinate[0], coordinate[1]); } catch (Exception e) { throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, IsochronesRequest.PARAM_LOCATIONS); } return realCoordinate; } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertSingleCoordinate() throws ParameterValueException { Coordinate coord = handler.convertSingleCoordinate(new Double[]{123.4, 321.0}); Assert.assertEquals(123.4, coord.x, 0.0001); Assert.assertEquals(321.0, coord.y, 0.0001); } @Test(expected = ParameterValueException.class) public void convertSingleCoordinateInvalidLengthShort() throws ParameterValueException { handler.convertSingleCoordinate(new Double[]{123.4}); } @Test(expected = ParameterValueException.class) public void convertSingleCoordinateInvalidLengthLong() throws ParameterValueException { handler.convertSingleCoordinate(new Double[]{123.4, 123.4, 123.4}); }
### Question: WheelchairSeparateWay extends PedestrianWay { @Override public boolean hasWayBeenFullyProcessed() { return hasBeenProcessed; } WheelchairSeparateWay(ReaderWay way); @Override boolean hasWayBeenFullyProcessed(); @Override void prepare(); }### Answer: @Test public void TestInitiallyNotProcessed() { assertFalse(way.hasWayBeenFullyProcessed()); }
### Question: BordersExtractor { public boolean isControlledBorder(int edgeId) { return storage.getEdgeValue(edgeId, BordersGraphStorage.Property.TYPE) == BordersGraphStorage.CONTROLLED_BORDER; } BordersExtractor(BordersGraphStorage storage, int[] avoidCountries); int getValue(int edgeId); boolean isBorder(int edgeId); boolean isControlledBorder(int edgeId); boolean isOpenBorder(int edgeId); boolean restrictedCountry(int edgeId); boolean isSameCountry(List<Integer> edgeIds); }### Answer: @Test public void TestDetectControlledBorder() { VirtualEdgeIteratorState ve1 = generateEdge(1); VirtualEdgeIteratorState ve2 = generateEdge(2); VirtualEdgeIteratorState ve3 = generateEdge(3); BordersExtractor be = new BordersExtractor(_graphstorage, new int[0]); assertEquals(true, be.isControlledBorder(1)); assertEquals(false, be.isControlledBorder(2)); assertEquals(false, be.isControlledBorder(3)); }
### Question: IsochronesRequestHandler extends GenericHandler { String[] convertAttributes(IsochronesRequestEnums.Attributes[] attributes) { return convertAPIEnumListToStrings(attributes); } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertAttributes() { IsochronesRequestEnums.Attributes[] atts = new IsochronesRequestEnums.Attributes[]{IsochronesRequestEnums.Attributes.AREA, IsochronesRequestEnums.Attributes.REACH_FACTOR, IsochronesRequestEnums.Attributes.TOTAL_POPULATION}; String[] attStr = handler.convertAttributes(atts); Assert.assertEquals("area", attStr[0]); Assert.assertEquals("reachfactor", attStr[1]); Assert.assertEquals("total_pop", attStr[2]); }
### Question: IsochronesRequestHandler extends GenericHandler { String convertCalcMethod(IsochronesRequestEnums.CalculationMethod bareCalcMethod) throws ParameterValueException { try { switch (bareCalcMethod) { case CONCAVE_BALLS: return "concaveballs"; case GRID: return "grid"; case FASTISOCHRONE: return "fastisochrone"; default: return "none"; } } catch (Exception ex) { throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, "calc_method"); } } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void convertCalcMethod() throws ParameterValueException { String calcMethod = handler.convertCalcMethod(IsochronesRequestEnums.CalculationMethod.CONCAVE_BALLS); Assert.assertEquals("concaveballs", calcMethod); calcMethod = handler.convertCalcMethod(IsochronesRequestEnums.CalculationMethod.GRID); Assert.assertEquals("grid", calcMethod); }
### Question: IsochronesRequestHandler extends GenericHandler { public IsochroneMapCollection getIsoMaps() { return isoMaps; } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void getIsoMapsTest() { IsochronesRequestHandler isochronesRequestHandler = new IsochronesRequestHandler(); Assert.assertNull(isochronesRequestHandler.getIsoMaps()); }
### Question: IsochronesRequestHandler extends GenericHandler { public IsochroneRequest getIsochroneRequest() { return isochroneRequest; } IsochronesRequestHandler(); void generateIsochronesFromRequest(IsochronesRequest request); IsochroneMapCollection getIsoMaps(); IsochroneRequest getIsochroneRequest(); }### Answer: @Test public void getIsochroneRequestTest() { IsochronesRequestHandler isochronesRequestHandler = new IsochronesRequestHandler(); Assert.assertNull(isochronesRequestHandler.getIsochroneRequest()); }
### Question: GenericHandler { protected String[] convertAPIEnumListToStrings(Enum[] valuesIn) { String[] attributes = new String[valuesIn.length]; for (int i = 0; i < valuesIn.length; i++) { attributes[i] = convertAPIEnum(valuesIn[i]); } return attributes; } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertAPIEnumListToStrings() { String[] strVals = handler.convertAPIEnumListToStrings(new APIEnums.ExtraInfo[] {APIEnums.ExtraInfo.STEEPNESS, APIEnums.ExtraInfo.SURFACE}); Assert.assertEquals(2, strVals.length); Assert.assertEquals("steepness", strVals[0]); Assert.assertEquals("surface", strVals[1]); }
### Question: GenericHandler { protected String convertAPIEnum(Enum valuesIn) { return valuesIn.toString(); } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertAPIEnum() { String strVal = handler.convertAPIEnum(APIEnums.AvoidBorders.CONTROLLED); Assert.assertEquals("controlled", strVal); }
### Question: OSMAttachedSidewalkProcessor { protected boolean hasSidewalkInfo(ReaderWay way) { return identifySidesWhereSidewalkIsPresent(way) != Side.NONE; } ReaderWay attachSidewalkTag(ReaderWay way, Side side); Side getPreparedSide(ReaderWay way); static final String KEY_ORS_SIDEWALK_SIDE; static final String VAL_RIGHT; static final String VAL_LEFT; }### Answer: @Test public void TestDetectSidewalkInfoFromTags() { ReaderWay way = new ReaderWay(1); way.setTag("sidewalk:left:surface", "asphalt"); assertTrue(processor.hasSidewalkInfo(way)); way = new ReaderWay(1); way.setTag("footway:right:width", "0.5"); assertTrue(processor.hasSidewalkInfo(way)); way = new ReaderWay(1); assertFalse(processor.hasSidewalkInfo(way)); }
### Question: GenericHandler { protected int convertVehicleType(APIEnums.VehicleType vehicleTypeIn, int profileType) throws IncompatibleParameterException { if (!RoutingProfileType.isHeavyVehicle(profileType)) { throw new IncompatibleParameterException(getInvalidParameterValueErrorCode(), "vehicle_type", vehicleTypeIn.toString(), KEY_PROFILE, RoutingProfileType.getName(profileType)); } if (vehicleTypeIn == null) { return HeavyVehicleAttributes.UNKNOWN; } return HeavyVehicleAttributes.getFromString(vehicleTypeIn.toString()); } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertVehicleType() throws IncompatibleParameterException { int type = handler.convertVehicleType(APIEnums.VehicleType.HGV, 2); Assert.assertEquals(2, type); } @Test(expected = IncompatibleParameterException.class) public void convertVehicleTypeError() throws IncompatibleParameterException { handler.convertVehicleType(APIEnums.VehicleType.HGV, 1); }
### Question: GenericHandler { protected BordersExtractor.Avoid convertAvoidBorders(APIEnums.AvoidBorders avoidBorders) { if (avoidBorders != null) { switch (avoidBorders) { case ALL: return BordersExtractor.Avoid.ALL; case CONTROLLED: return BordersExtractor.Avoid.CONTROLLED; default: return BordersExtractor.Avoid.NONE; } } return null; } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertAvoidBorders() { BordersExtractor.Avoid avoid = handler.convertAvoidBorders(APIEnums.AvoidBorders.CONTROLLED); Assert.assertEquals(BordersExtractor.Avoid.CONTROLLED, avoid); avoid = handler.convertAvoidBorders(APIEnums.AvoidBorders.ALL); Assert.assertEquals(BordersExtractor.Avoid.ALL, avoid); avoid = handler.convertAvoidBorders(APIEnums.AvoidBorders.NONE); Assert.assertEquals(BordersExtractor.Avoid.NONE, avoid); }
### Question: GenericHandler { protected int convertRouteProfileType(APIEnums.Profile profile) { return RoutingProfileType.getFromString(profile.toString()); } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertRouteProfileType() { int type = handler.convertRouteProfileType(APIEnums.Profile.DRIVING_CAR); Assert.assertEquals(1, type); type = handler.convertRouteProfileType(APIEnums.Profile.FOOT_WALKING); Assert.assertEquals(20, type); }
### Question: GenericHandler { protected int convertFeatureTypes(APIEnums.AvoidFeatures[] avoidFeatures, int profileType) throws UnknownParameterValueException, IncompatibleParameterException { int flags = 0; for (APIEnums.AvoidFeatures avoid : avoidFeatures) { String avoidFeatureName = avoid.toString(); int flag = AvoidFeatureFlags.getFromString(avoidFeatureName); if (flag == 0) throw new UnknownParameterValueException(getInvalidParameterValueErrorCode(), "avoid_features", avoidFeatureName); if (!AvoidFeatureFlags.isValid(profileType, flag)) throw new IncompatibleParameterException(getInvalidParameterValueErrorCode(), "avoid_features", avoidFeatureName, KEY_PROFILE, RoutingProfileType.getName(profileType)); flags |= flag; } return flags; } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertFeatureTypes() throws UnknownParameterValueException, IncompatibleParameterException { APIEnums.AvoidFeatures[] avoids = new APIEnums.AvoidFeatures[] { APIEnums.AvoidFeatures.FERRIES, APIEnums.AvoidFeatures.FORDS }; int converted = handler.convertFeatureTypes(avoids, 1); Assert.assertEquals(24, converted); } @Test(expected = IncompatibleParameterException.class) public void convertFeatureTypesIncompatible() throws UnknownParameterValueException, IncompatibleParameterException { APIEnums.AvoidFeatures[] avoids = new APIEnums.AvoidFeatures[] { APIEnums.AvoidFeatures.STEPS}; handler.convertFeatureTypes(avoids, 1); }
### Question: GenericHandler { protected ProfileParameters convertParameters(RouteRequestOptions options, int profileType) throws StatusCodeException { ProfileParameters params = new ProfileParameters(); if (options.getProfileParams().hasRestrictions()) { RequestProfileParamsRestrictions restrictions = options.getProfileParams().getRestrictions(); APIEnums.VehicleType vehicleType = options.getVehicleType(); validateRestrictionsForProfile(restrictions, profileType); params = convertSpecificProfileParameters(profileType, restrictions, vehicleType); } if (options.getProfileParams().hasWeightings()) { RequestProfileParamsWeightings weightings = options.getProfileParams().getWeightings(); applyWeightings(weightings, params); } return params; } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertParameters() throws StatusCodeException { RouteRequestOptions opts = new RouteRequestOptions(); RequestProfileParams params = new RequestProfileParams(); RequestProfileParamsRestrictions restrictions = new RequestProfileParamsRestrictions(); restrictions.setHeight(10.0f); params.setRestrictions(restrictions); opts.setVehicleType(APIEnums.VehicleType.HGV); opts.setProfileParams(params); ProfileParameters generatedParams = handler.convertParameters(opts, 2); Assert.assertEquals(10.0f, ((VehicleParameters)generatedParams).getHeight(), 0.0); }
### Question: GenericHandler { protected ProfileParameters convertSpecificProfileParameters(int profileType, RequestProfileParamsRestrictions restrictions, APIEnums.VehicleType vehicleType) { ProfileParameters params = new ProfileParameters(); if (RoutingProfileType.isHeavyVehicle(profileType)) params = convertHeavyVehicleParameters(restrictions, vehicleType); if (RoutingProfileType.isWheelchair(profileType)) params = convertWheelchairParameters(restrictions); return params; } GenericHandler(); static final String KEY_PROFILE; }### Answer: @Test public void convertSpecificProfileParameters() { RequestProfileParamsRestrictions restrictions = new RequestProfileParamsRestrictions(); restrictions.setHeight(10.0f); ProfileParameters params = handler.convertSpecificProfileParameters(2, restrictions, APIEnums.VehicleType.HGV); Assert.assertTrue(params instanceof VehicleParameters); Assert.assertEquals(10.0f, ((VehicleParameters)params).getHeight(), 0.0); }
### Question: Contour { public void calculateContour() { handleBaseCells(); cellStorage.flush(); IntObjectMap<IntHashSet> superCells = handleSuperCells(); cellStorage.storeContourPointerMap(); if (isSupercellsEnabled()) cellStorage.storeSuperCells(superCells); cellStorage.setContourPrepared(true); cellStorage.flush(); } Contour(GraphHopperStorage ghStorage, NodeAccess nodeAccess, IsochroneNodeStorage isochroneNodeStorage, CellStorage cellStorage); static double distance(double lat1, double lat2, double lon1, double lon2); void calculateContour(); Contour setGhStorage(GraphHopperStorage ghStorage); }### Answer: @Test public void testCalculateContour() { GraphHopperStorage graphHopperStorage = ToyGraphCreationUtil.createSimpleGraph(encodingManager); createMockStorages(graphHopperStorage); Contour contour = new Contour(graphHopperStorage, graphHopperStorage.getBaseGraph().getNodeAccess(), ins, cs); contour.calculateContour(); List<Double> coordinatesCell2 = cs.getCellContourOrder(2); assertEquals(2686, coordinatesCell2.size()); assertEquals(3.0, coordinatesCell2.get(0), 1e-10); assertEquals(1.0, coordinatesCell2.get(1), 1e-10); assertEquals(3.0, coordinatesCell2.get(2), 1e-10); assertEquals(1.003596954128078, coordinatesCell2.get(3), 1e-10); assertEquals(3.0, coordinatesCell2.get(2684), 1e-10); assertEquals(1.0, coordinatesCell2.get(2685), 1e-10); }
### Question: Contour { public static double distance(double lat1, double lat2, double lon1, double lon2) { final int R = 6371; double latDistance = Math.toRadians(lat2 - lat1); double lonDistance = Math.toRadians(lon2 - lon1); double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = R * c * 1000; distance = Math.pow(distance, 2); return Math.sqrt(distance); } Contour(GraphHopperStorage ghStorage, NodeAccess nodeAccess, IsochroneNodeStorage isochroneNodeStorage, CellStorage cellStorage); static double distance(double lat1, double lat2, double lon1, double lon2); void calculateContour(); Contour setGhStorage(GraphHopperStorage ghStorage); }### Answer: @Test public void testDistance() { double distance = Contour.distance(1, 1, 1, 2); assertEquals(111177.99068882648, distance, 1e-10); double distance2 = Contour.distance(1, 1, 0.5, -0.5); assertEquals(111177.99068882648, distance2, 1e-10); }
### Question: ActiveCellDijkstra extends AbstractIsochroneDijkstra { protected void addInitialBordernode(int nodeId, double weight) { SPTEntry entry = new SPTEntry(nodeId, weight); fromHeap.add(entry); fromMap.put(nodeId, entry); } ActiveCellDijkstra(Graph graph, Weighting weighting, IsochroneNodeStorage isochroneNodeStorage, int cellId); void setIsochroneLimit(double limit); @Override String getName(); }### Answer: @Test public void testAddInitialBorderNode() { GraphHopperStorage graphHopperStorage = ToyGraphCreationUtil.createMediumGraph(encodingManager); createMockStorages(graphHopperStorage); Weighting shortestWeighting = new ShortestWeighting(carEncoder); ActiveCellDijkstra activeCellDijkstra = new ActiveCellDijkstra(graphHopperStorage.getBaseGraph(), shortestWeighting, ins, 2); activeCellDijkstra.setIsochroneLimit(5000); for (int nodeId : new int[]{3, 8}) { activeCellDijkstra.addInitialBordernode(nodeId, 0); } SPTEntry entry = activeCellDijkstra.fromHeap.poll(); assertEquals(3, entry.adjNode); assertEquals(0.0, entry.getWeightOfVisitedPath(), 1e-10); entry = activeCellDijkstra.fromHeap.poll(); assertEquals(8, entry.adjNode); assertEquals(0.0, entry.getWeightOfVisitedPath(), 1e-10); assertEquals(2, activeCellDijkstra.getFromMap().size()); }
### Question: RangeDijkstra extends AbstractIsochroneDijkstra { private void getMaxWeight() { for (IntObjectCursor<SPTEntry> entry : fromMap) { if (USERELEVANTONLY && !relevantNodes.contains(entry.key)) continue; if (maximumWeight < entry.value.weight) maximumWeight = entry.value.weight; } } RangeDijkstra(Graph graph, Weighting weighting); double calcMaxWeight(int from, IntHashSet relevantNodes); void setCellNodes(IntHashSet cellNodes); int getFoundCellNodeSize(); @Override String getName(); }### Answer: @Test public void testGetMaxWeight() { GraphHopperStorage graphHopperStorage = createSimpleGraph(); RangeDijkstra rangeDijkstra = new RangeDijkstra(graphHopperStorage.getBaseGraph(), new ShortestWeighting(carEncoder)); rangeDijkstra.setMaxVisitedNodes(getMaxCellNodesNumber() * 10); IntHashSet cellNodes = new IntHashSet(); IntHashSet relevantNodes = new IntHashSet(); cellNodes.addAll(0, 1, 2, 5); relevantNodes.addAll(0, 1, 2); rangeDijkstra.setCellNodes(cellNodes); assertEquals(3.0, rangeDijkstra.calcMaxWeight(0, cellNodes), 1e-10); rangeDijkstra = new RangeDijkstra(graphHopperStorage.getBaseGraph(), new ShortestWeighting(carEncoder)); rangeDijkstra.setMaxVisitedNodes(getMaxCellNodesNumber() * 10); rangeDijkstra.setCellNodes(cellNodes); assertEquals(1.0, rangeDijkstra.calcMaxWeight(0, relevantNodes), 1e-10); }
### Question: PartitioningDataBuilder { PartitioningDataBuilder(Graph graph, PartitioningData pData) { this.graph = graph; this.pData = pData; } PartitioningDataBuilder(Graph graph, PartitioningData pData); void run(); }### Answer: @Test public void testPartitioningDataBuilder() { GraphHopperStorage ghStorage = ToyGraphCreationUtil.createMediumGraph(encodingManager); PartitioningData pData = new PartitioningData(); EdgeFilter edgeFilter = new EdgeFilterSequence(); PartitioningDataBuilder partitioningDataBuilder = new PartitioningDataBuilder(ghStorage.getBaseGraph(), pData); partitioningDataBuilder.run(); assertEquals(28, pData.flowEdgeBaseNode.length); assertEquals(28, pData.flow.length); assertEquals(0, pData.flowEdgeBaseNode[0]); assertEquals(1, pData.flowEdgeBaseNode[1]); assertEquals(0, pData.flowEdgeBaseNode[2]); assertEquals(2, pData.flowEdgeBaseNode[3]); assertEquals(10, pData.visited.length); assertEquals(0, pData.visited[0]); }
### Question: Projector { protected List<Projection> calculateProjectionOrder(Map<Projection, IntArrayList> projections) { List<Projection> order; EnumMap<Projection, Double> squareRangeProjMap = new EnumMap<>(Projection.class); EnumMap<Projection, Double> orthogonalDiffProjMap = new EnumMap<>(Projection.class); for (Map.Entry<Projection, IntArrayList> proj : projections.entrySet()) { int idx = (int) (proj.getValue().size() * getSplitValue()); squareRangeProjMap.put(proj.getKey(), projIndividualValue(projections, proj.getKey(), idx)); } for (Projection proj : projections.keySet()) { orthogonalDiffProjMap.put(proj, projCombinedValue(squareRangeProjMap, proj)); } Sort sort = new Sort(); order = sort.sortByValueReturnList(orthogonalDiffProjMap, false); return order; } Projector(); void setGHStorage(GraphHopperStorage ghStorage); }### Answer: @Test public void testCalculateProjectionOrder() { double originalSplitValue = getSplitValue(); setSplitValue(0); Projector projector = new Projector(); projector.setGHStorage(ToyGraphCreationUtil.createMediumGraph2(encodingManager)); Map<Projector.Projection, IntArrayList> projections = projector.calculateProjections(); List<Projector.Projection> projectionOrder = projector.calculateProjectionOrder(projections); assertEquals(Projector.Projection.LINE_P675, projectionOrder.get(0)); assertEquals(Projector.Projection.LINE_P45, projectionOrder.get(1)); assertEquals(Projector.Projection.LINE_M225, projectionOrder.get(7)); setSplitValue(originalSplitValue); }
### Question: MaxFlowMinCut { protected void reset() { resetAlgorithm(); resetData(); } MaxFlowMinCut(Graph graph, PartitioningData pData, EdgeFilter edgeFilter); void setVisited(int node); boolean isVisited(int visited); void setUnvisitedAll(); abstract int getMaxFlow(); BiPartition calcNodePartition(); void setNodeOrder(); void setOrderedNodes(IntArrayList orderedNodes); void setAdditionalEdgeFilter(EdgeFilter edgeFilter); }### Answer: @Test public void testReset() { GraphHopperStorage graphHopperStorage = ToyGraphCreationUtil.createMediumGraph(encodingManager); Graph graph = graphHopperStorage.getBaseGraph(); int[] flowEdgeBaseNode = new int[]{ 0, 1, 0, 2, 0, 3, 0, 8, 1, 2, 1, 8, 2, 3, 3, 4, 4, 5, 4, 6, 5, 7, 6, 7, 7, 8, -1, -1 }; boolean[] flow = new boolean[]{ false, true, false, true, false, true, false, false, true, false, true, false, true, false, false, true, false, true, false, true, false, false, true, false, true, false, false, false }; int[] visited = new int[]{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 }; PartitioningData pData = new PartitioningData(flowEdgeBaseNode, flow, visited); IntArrayList projection_m00 = new IntArrayList(); projection_m00.add(1, 2, 3, 0, 4, 6, 8, 5, 7); MaxFlowMinCut maxFlowMinCut = new EdmondsKarpAStar(graph, pData, null); maxFlowMinCut.setOrderedNodes(projection_m00); maxFlowMinCut.setNodeOrder(); maxFlowMinCut.reset(); for (boolean f : pData.flow) assertEquals(false, f); for (int v : pData.visited) assertEquals(0, v); }
### Question: CountryBordersPolygon { public String getName() { return this.name; } CountryBordersPolygon(String name, Geometry boundary); double[] getBBox(); boolean shares(MultiPolygon other); boolean crossesBoundary(LineString line); String getName(); MultiPolygon getBoundary(); boolean inBbox(Coordinate c); boolean inArea(Coordinate c); double getArea(); }### Answer: @Test public void TestName() { assertEquals("name", cbp.getName()); }
### Question: CountryBordersPolygon { public MultiPolygon getBoundary() { return this.boundary; } CountryBordersPolygon(String name, Geometry boundary); double[] getBBox(); boolean shares(MultiPolygon other); boolean crossesBoundary(LineString line); String getName(); MultiPolygon getBoundary(); boolean inBbox(Coordinate c); boolean inArea(Coordinate c); double getArea(); }### Answer: @Test public void TestBoundaryGeometry() { MultiPolygon boundary = cbp.getBoundary(); Coordinate[] cbpCoords = boundary.getCoordinates(); assertEquals(country1Geom.length, cbpCoords.length); assertEquals(country1Geom[0].x, cbpCoords[0].x, 0.0); assertEquals(country1Geom[3].y, cbpCoords[3].y,0.0); }
### Question: CountryBordersPolygon { public double[] getBBox() { return new double[] {minLon, maxLon, minLat, maxLat}; } CountryBordersPolygon(String name, Geometry boundary); double[] getBBox(); boolean shares(MultiPolygon other); boolean crossesBoundary(LineString line); String getName(); MultiPolygon getBoundary(); boolean inBbox(Coordinate c); boolean inArea(Coordinate c); double getArea(); }### Answer: @Test public void TestBBox() { double[] bbox = cbp.getBBox(); assertEquals(-1.0, bbox[0], 0.0); assertEquals(1.0, bbox[1], 0.0); assertEquals(-1.0, bbox[2], 0.0); assertEquals(2.0, bbox[3], 0.0); }
### Question: CountryBordersPolygon { public boolean crossesBoundary(LineString line) { return this.boundaryLine.intersects(line); } CountryBordersPolygon(String name, Geometry boundary); double[] getBBox(); boolean shares(MultiPolygon other); boolean crossesBoundary(LineString line); String getName(); MultiPolygon getBoundary(); boolean inBbox(Coordinate c); boolean inArea(Coordinate c); double getArea(); }### Answer: @Test public void TestIntersection() { LineString ls = gf.createLineString(new Coordinate[] { new Coordinate(0.5, 0.5), new Coordinate(-10.5, -10.5) }); assertTrue(cbp.crossesBoundary(ls)); ls = gf.createLineString(new Coordinate[] { new Coordinate(0.5, 0.5), new Coordinate(0.25, 0.25) }); assertFalse(cbp.crossesBoundary(ls)); }
### Question: CountryBordersPolygon { public boolean inBbox(Coordinate c) { return !(c.x < minLon || c.x > maxLon || c.y < minLat || c.y > maxLat); } CountryBordersPolygon(String name, Geometry boundary); double[] getBBox(); boolean shares(MultiPolygon other); boolean crossesBoundary(LineString line); String getName(); MultiPolygon getBoundary(); boolean inBbox(Coordinate c); boolean inArea(Coordinate c); double getArea(); }### Answer: @Test public void TestBBoxContains() { assertTrue(cbp.inBbox(new Coordinate(0.5, 0.5))); assertFalse(cbp.inBbox(new Coordinate(10.0, 0.5))); }
### Question: BordersExtractor { public boolean isOpenBorder(int edgeId) { return storage.getEdgeValue(edgeId, BordersGraphStorage.Property.TYPE) == BordersGraphStorage.OPEN_BORDER; } BordersExtractor(BordersGraphStorage storage, int[] avoidCountries); int getValue(int edgeId); boolean isBorder(int edgeId); boolean isControlledBorder(int edgeId); boolean isOpenBorder(int edgeId); boolean restrictedCountry(int edgeId); boolean isSameCountry(List<Integer> edgeIds); }### Answer: @Test public void TestDetectOpenBorder() { VirtualEdgeIteratorState ve1 = generateEdge(1); VirtualEdgeIteratorState ve2 = generateEdge(2); VirtualEdgeIteratorState ve3 = generateEdge(3); BordersExtractor be = new BordersExtractor(_graphstorage, new int[0]); assertEquals(false, be.isOpenBorder(1)); assertEquals(true, be.isOpenBorder(2)); assertEquals(false, be.isOpenBorder(3)); }
### Question: CountryBordersPolygon { public boolean inArea(Coordinate c) { if(!Double.isNaN(c.x) && !Double.isNaN(c.y) && inBbox(c)) { GeometryFactory gf = new GeometryFactory(); return boundary.contains(gf.createPoint(c)); } return false; } CountryBordersPolygon(String name, Geometry boundary); double[] getBBox(); boolean shares(MultiPolygon other); boolean crossesBoundary(LineString line); String getName(); MultiPolygon getBoundary(); boolean inBbox(Coordinate c); boolean inArea(Coordinate c); double getArea(); }### Answer: @Test public void TestPolygonContains() { assertTrue(cbp.inArea(new Coordinate(0.5, 0.5))); assertFalse(cbp.inArea(new Coordinate(-0.5, -0.5))); }
### Question: CountryBordersReader { public CountryBordersPolygon[] getCountry(Coordinate c) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); Iterator it = hierarchies.entrySet().iterator(); while(it.hasNext()) { Map.Entry<Long, CountryBordersHierarchy> pair = (Map.Entry)it.next(); CountryBordersHierarchy h = pair.getValue(); if(h.inBbox(c)) { List<CountryBordersPolygon> ps = h.getPolygons(); for(CountryBordersPolygon cp : ps) { if(cp.inBbox(c) && cp.inArea(c)) { countries.add(cp); } } } } return countries.toArray(new CountryBordersPolygon[countries.size()]); } CountryBordersReader(); CountryBordersReader(String filepath, String idsPath, String openPath); void addHierarchy(Long id, CountryBordersHierarchy hierarchy); void addId(String id, String localName, String englishName, String cca2, String cca3); void addOpenBorder(String country1, String country2); CountryBordersPolygon[] getCountry(Coordinate c); CountryBordersPolygon[] getCandidateCountry(Coordinate c); String getId(String name); String getEngName(String name); boolean isOpen(String c1, String c2); static int getCountryIdByISOCode(String code); static final String INTERNATIONAL_NAME; static final String INTERNATIONAL_ID; static final String KEY_PROPERTIES; }### Answer: @Test public void TestGetCountry() { Coordinate c = new Coordinate(0.5, 0.5); CountryBordersPolygon[] polys = _reader.getCountry(c); assertEquals(1, polys.length); assertEquals("country1", polys[0].getName()); }
### Question: CountryBordersReader { public CountryBordersPolygon[] getCandidateCountry(Coordinate c) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); Iterator it = hierarchies.entrySet().iterator(); while(it.hasNext()) { Map.Entry<Long, CountryBordersHierarchy> pair = (Map.Entry)it.next(); CountryBordersHierarchy h = pair.getValue(); if(h.inBbox(c)) { List<CountryBordersPolygon> ps = h.getPolygons(); for(CountryBordersPolygon cp : ps) { if(cp.inBbox(c)) { countries.add(cp); } } } } return countries.toArray(new CountryBordersPolygon[countries.size()]); } CountryBordersReader(); CountryBordersReader(String filepath, String idsPath, String openPath); void addHierarchy(Long id, CountryBordersHierarchy hierarchy); void addId(String id, String localName, String englishName, String cca2, String cca3); void addOpenBorder(String country1, String country2); CountryBordersPolygon[] getCountry(Coordinate c); CountryBordersPolygon[] getCandidateCountry(Coordinate c); String getId(String name); String getEngName(String name); boolean isOpen(String c1, String c2); static int getCountryIdByISOCode(String code); static final String INTERNATIONAL_NAME; static final String INTERNATIONAL_ID; static final String KEY_PROPERTIES; }### Answer: @Test public void TestGetCandidateCountry() { Coordinate c = new Coordinate(-0.25, -0.25); CountryBordersPolygon[] polys = _reader.getCandidateCountry(c); assertEquals(1, polys.length); assertEquals("country3", polys[0].getName()); }
### Question: CountryBordersReader { public String getId(String name) { if(name.equals(INTERNATIONAL_NAME)) return INTERNATIONAL_ID; if(ids.containsKey(name)) return ids.get(name).id; else return ""; } CountryBordersReader(); CountryBordersReader(String filepath, String idsPath, String openPath); void addHierarchy(Long id, CountryBordersHierarchy hierarchy); void addId(String id, String localName, String englishName, String cca2, String cca3); void addOpenBorder(String country1, String country2); CountryBordersPolygon[] getCountry(Coordinate c); CountryBordersPolygon[] getCandidateCountry(Coordinate c); String getId(String name); String getEngName(String name); boolean isOpen(String c1, String c2); static int getCountryIdByISOCode(String code); static final String INTERNATIONAL_NAME; static final String INTERNATIONAL_ID; static final String KEY_PROPERTIES; }### Answer: @Test public void TestGetCountryId() { assertEquals("1", _reader.getId("country1")); }
### Question: CountryBordersReader { public String getEngName(String name) { if(name.equals(INTERNATIONAL_NAME)) return INTERNATIONAL_NAME; if(ids.containsKey(name)) return ids.get(name).nameEng; else return ""; } CountryBordersReader(); CountryBordersReader(String filepath, String idsPath, String openPath); void addHierarchy(Long id, CountryBordersHierarchy hierarchy); void addId(String id, String localName, String englishName, String cca2, String cca3); void addOpenBorder(String country1, String country2); CountryBordersPolygon[] getCountry(Coordinate c); CountryBordersPolygon[] getCandidateCountry(Coordinate c); String getId(String name); String getEngName(String name); boolean isOpen(String c1, String c2); static int getCountryIdByISOCode(String code); static final String INTERNATIONAL_NAME; static final String INTERNATIONAL_ID; static final String KEY_PROPERTIES; }### Answer: @Test public void TestGetCountryEnglishName() { assertEquals("country1 English", _reader.getEngName("country1")); }
### Question: CountryBordersReader { public boolean isOpen(String c1, String c2) { if(openBorders.containsKey(c1)) { return openBorders.get(c1).contains(c2); } else if(openBorders.containsKey(c2)) return openBorders.get(c2).contains(c1); return false; } CountryBordersReader(); CountryBordersReader(String filepath, String idsPath, String openPath); void addHierarchy(Long id, CountryBordersHierarchy hierarchy); void addId(String id, String localName, String englishName, String cca2, String cca3); void addOpenBorder(String country1, String country2); CountryBordersPolygon[] getCountry(Coordinate c); CountryBordersPolygon[] getCandidateCountry(Coordinate c); String getId(String name); String getEngName(String name); boolean isOpen(String c1, String c2); static int getCountryIdByISOCode(String code); static final String INTERNATIONAL_NAME; static final String INTERNATIONAL_ID; static final String KEY_PROPERTIES; }### Answer: @Test public void TestGetOpenBorder() { assertTrue(_reader.isOpen("country1", "country2")); assertFalse(_reader.isOpen("country1", "country3")); }
### Question: CountryBordersReader { public static int getCountryIdByISOCode(String code) { return currentInstance != null ? currentInstance.isoCodes.getOrDefault(code.toUpperCase(), 0) : 0; } CountryBordersReader(); CountryBordersReader(String filepath, String idsPath, String openPath); void addHierarchy(Long id, CountryBordersHierarchy hierarchy); void addId(String id, String localName, String englishName, String cca2, String cca3); void addOpenBorder(String country1, String country2); CountryBordersPolygon[] getCountry(Coordinate c); CountryBordersPolygon[] getCandidateCountry(Coordinate c); String getId(String name); String getEngName(String name); boolean isOpen(String c1, String c2); static int getCountryIdByISOCode(String code); static final String INTERNATIONAL_NAME; static final String INTERNATIONAL_ID; static final String KEY_PROPERTIES; }### Answer: @Test public void TestGetCountryIdByISOCode() { assertEquals(1, CountryBordersReader.getCountryIdByISOCode("CT")); assertEquals(1, CountryBordersReader.getCountryIdByISOCode("CTR")); assertEquals(0, CountryBordersReader.getCountryIdByISOCode("FOO")); }
### Question: CountryBordersHierarchy { public double[] getBBox() { return new double[] {minLon, maxLon, minLat, maxLat}; } void add(CountryBordersPolygon cp); boolean inBbox(Coordinate c); double[] getBBox(); List<CountryBordersPolygon> getPolygons(); List<CountryBordersPolygon> getContainingPolygons(Coordinate c); }### Answer: @Test public void GetBBoxTest() { double[] bbox = cbh1.getBBox(); assertEquals(-1.0, bbox[0], 0.0); assertEquals(1.0, bbox[1], 0.0); assertEquals(-1.0, bbox[2], 0.0); assertEquals(1.0, bbox[3], 0.0); bbox = cbh2.getBBox(); assertEquals(5.0, bbox[0], 0.0); assertEquals(10.0, bbox[1], 0.0); assertEquals(5.0, bbox[2], 0.0); assertEquals(10.0, bbox[3], 0.0); }
### Question: CountryBordersHierarchy { public boolean inBbox(Coordinate c) { return !(c.x <= minLon || c.x >= maxLon || c.y <= minLat || c.y >= maxLat); } void add(CountryBordersPolygon cp); boolean inBbox(Coordinate c); double[] getBBox(); List<CountryBordersPolygon> getPolygons(); List<CountryBordersPolygon> getContainingPolygons(Coordinate c); }### Answer: @Test public void InBBoxTest() { assertTrue(cbh1.inBbox(new Coordinate(0.5, 0.5))); assertTrue(cbh1.inBbox(new Coordinate(-0.5, 0.5))); assertFalse(cbh1.inBbox(new Coordinate(7.5, 7.5))); assertFalse(cbh1.inBbox(new Coordinate(100, 100))); }
### Question: CountryBordersHierarchy { public List<CountryBordersPolygon> getContainingPolygons(Coordinate c) { ArrayList<CountryBordersPolygon> containing = new ArrayList<>(); if(!Double.isNaN(c.x) && !Double.isNaN(c.y) && inBbox(c)) { for (CountryBordersPolygon cbp : polygons) { if (cbp.inBbox(c)) { containing.add(cbp); } } } return containing; } void add(CountryBordersPolygon cp); boolean inBbox(Coordinate c); double[] getBBox(); List<CountryBordersPolygon> getPolygons(); List<CountryBordersPolygon> getContainingPolygons(Coordinate c); }### Answer: @Test public void GetCountryTest() { List<CountryBordersPolygon> containing = cbh1.getContainingPolygons(new Coordinate(0.9, 0.9)); assertEquals(1, containing.size()); assertEquals("name1", containing.get(0).getName()); containing = cbh1.getContainingPolygons(new Coordinate(0.0, 0.0)); assertEquals(2, containing.size()); containing = cbh1.getContainingPolygons(new Coordinate(10, 10)); assertEquals(0, containing.size()); }
### Question: BordersExtractor { public boolean restrictedCountry(int edgeId) { int startCountry = storage.getEdgeValue(edgeId, BordersGraphStorage.Property.START); int endCountry = storage.getEdgeValue(edgeId, BordersGraphStorage.Property.END); for(int i = 0; i< avoidCountries.length; i++) { if(startCountry == avoidCountries[i] || endCountry == avoidCountries[i] ) { return true; } } return false; } BordersExtractor(BordersGraphStorage storage, int[] avoidCountries); int getValue(int edgeId); boolean isBorder(int edgeId); boolean isControlledBorder(int edgeId); boolean isOpenBorder(int edgeId); boolean restrictedCountry(int edgeId); boolean isSameCountry(List<Integer> edgeIds); }### Answer: @Test public void TestAvoidCountry() { VirtualEdgeIteratorState ve1 = generateEdge(1); VirtualEdgeIteratorState ve2 = generateEdge(2); VirtualEdgeIteratorState ve3 = generateEdge(3); BordersExtractor be = new BordersExtractor(_graphstorage, new int[] {2, 4}); assertEquals(true, be.restrictedCountry(1)); assertEquals(true, be.restrictedCountry(2)); assertEquals(false, be.restrictedCountry(3)); }
### Question: BordersExtractor { public boolean isSameCountry(List<Integer> edgeIds){ if(edgeIds.isEmpty()) return true; short country0 = storage.getEdgeValue(edgeIds.get(0), BordersGraphStorage.Property.START); short country1 = storage.getEdgeValue(edgeIds.get(0), BordersGraphStorage.Property.END); for(int edgeId : edgeIds) { short country2 = storage.getEdgeValue(edgeId, BordersGraphStorage.Property.START); short country3 = storage.getEdgeValue(edgeId, BordersGraphStorage.Property.END); if(country0 != country2 && country0 != country3 && country1 != country2 && country1 != country3) return false; } return true; } BordersExtractor(BordersGraphStorage storage, int[] avoidCountries); int getValue(int edgeId); boolean isBorder(int edgeId); boolean isControlledBorder(int edgeId); boolean isOpenBorder(int edgeId); boolean restrictedCountry(int edgeId); boolean isSameCountry(List<Integer> edgeIds); }### Answer: @Test public void TestIsSameCountry() { VirtualEdgeIteratorState ve1 = generateEdge(1); VirtualEdgeIteratorState ve2 = generateEdge(2); VirtualEdgeIteratorState ve3 = generateEdge(3); BordersExtractor be = new BordersExtractor(_graphstorage, new int[] {2, 4}); List<Integer> countries = new ArrayList<>(); countries.add(1); countries.add(2); assertFalse(be.isSameCountry(countries)); countries = new ArrayList<>(); countries.add(3); countries.add(4); assertTrue(be.isSameCountry(countries)); countries = new ArrayList<>(); countries.add(4); countries.add(5); assertFalse(be.isSameCountry(countries)); countries = new ArrayList<>(); countries.add(5); countries.add(6); assertTrue(be.isSameCountry(countries)); }