/** * Extracts the names of abstract types. * @param types a non-null list of types * @return a non-null list of string */ public static List<String> extractNames( Collection<? extends AbstractType> types ) { List<String> result = new ArrayList<> (); for( AbstractType t : types ) result.add( t.getName()); return result; }
/** * Fixes the name of an exported variable name. * <p> * An exported variable must ALWAYS be prefixed with the name of the "type" * that exports it. * </p> * * @param type a facet or a component * @param exportedVariableName the name of an exported variable * @return a non-null string */ static String fixVariableName( AbstractType type, String exportedVariableName ) { String prefix = type.getName() + "."; String result = exportedVariableName; if( ! result.startsWith( prefix )) result = prefix + exportedVariableName; return result; }
/** * Computes an horizontal margin for a given node. * <p> * We used to have a static horizontal margin, but images were * truncated for long names. See roboconf-platform#315 * </p> * * @param input a node (can be null) * @return a positive integer */ private static int computeHMargin( AbstractType input ) { int basis = MIN_H_MARGIN; if( input != null && input.getName().length() > 17 ) { // Beyond 17 characters, we give 3 pixels for every new characters. basis += 3 * (input.getName().length() - 17); } return basis; } }
@Override public boolean equals( Object obj ) { return obj != null && obj.getClass().equals( getClass()) && Objects.equals( this.name, ((AbstractType) obj).getName()); }
/** * Computes an horizontal margin for a given node. * <p> * We used to have a static horizontal margin, but images were * truncated for long names. See roboconf-platform#315 * </p> * * @param input a node (can be null) * @return a positive integer */ private static int computeHMargin( AbstractType input ) { int basis = MIN_H_MARGIN; if( input != null && input.getName().length() > 17 ) { // Beyond 17 characters, we give 3 pixels for every new characters. basis += 3 * (input.getName().length() - 17); } return basis; } }
private String writeCollection( Collection<? extends AbstractType> types ) { StringBuilder sb = new StringBuilder(); for( Iterator<? extends AbstractType> it=types.iterator(); it.hasNext(); ) { sb.append( it.next().getName()); if( it.hasNext()) sb.append( ", " ); } return sb.toString(); } }
/** * Computes the width of a shape for a given component or facet. * @param type a type * @return the width it should take once displayed as a graph vertex */ public static int computeShapeWidth( AbstractType type ) { Font font = GraphUtils.getDefaultFont(); BufferedImage img = new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB ); FontMetrics fm = img.getGraphics().getFontMetrics( font ); int width = fm.stringWidth( type.getName()); width = Math.max( width, 80 ) + 20; return width; }
/** * Computes the width of a shape for a given component or facet. * @param type a type * @return the width it should take once displayed as a graph vertex */ public static int computeShapeWidth( AbstractType type ) { Font font = GraphUtils.getDefaultFont(); BufferedImage img = new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB ); FontMetrics fm = img.getGraphics().getFontMetrics( font ); int width = fm.stringWidth( type.getName()); width = Math.max( width, 80 ) + 20; return width; }
private void checkUnicity() { // Components for( Data<?> data : this.componentNameToComponentData.values()) { if( data.blocks.size() > 1 ) this.errors.addAll( data.error( ErrorCode.CO_ALREADY_DEFINED_COMPONENT, component( data.object.getName()))); } // Facets for( Data<?> data : this.facetNameToFacetData.values()) { if( data.blocks.size() > 1 ) this.errors.addAll( data.error( ErrorCode.CO_ALREADY_DEFINED_FACET, facet( data.object.getName()))); } }
@Test public void testSortingWithNull() { List<AbstractType> types = new ArrayList<AbstractType> (); types.add( new Facet( "z" )); types.add( null ); types.add( new Component( "m" )); Assert.assertEquals( "z", types.get( 0 ).getName()); Collections.sort( types, new AbstractTypeComparator()); Assert.assertEquals( "m", types.get( 0 ).getName()); Assert.assertEquals( "z", types.get( 1 ).getName()); Assert.assertNull( types.get( 2 )); } }
@Test public void testMixedSorting() { List<AbstractType> types = new ArrayList<AbstractType> (); types.add( new Facet( "z" )); types.add( new Component( "m" )); types.add( new Component( "a" )); types.add( new Facet( "b" )); Assert.assertEquals( "z", types.get( 0 ).getName()); Collections.sort( types, new AbstractTypeComparator()); Assert.assertEquals( "a", types.get( 0 ).getName()); Assert.assertEquals( "b", types.get( 1 ).getName()); Assert.assertEquals( "m", types.get( 2 ).getName()); Assert.assertEquals( "z", types.get( 3 ).getName()); }
errors.add( new ModelError( RM_UNREACHABLE_COMPONENT, t, component( t.getName())));
Assert.assertNotNull( c ); Assert.assertEquals( 1, c.getChildren().size()); Assert.assertEquals( ComplexApplicationFactory1.APP_3, c.getChildren().iterator().next().getName());