Java Code Examples for org.eclipse.emf.common.util.EList#size()

The following examples show how to use org.eclipse.emf.common.util.EList#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConvertingCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * On Java-level the any-type is represented as java.lang.Object as there is no subtype of everything (i.e. type for null).
 * So, when the values are used we need to manually cast them to whatever is expected.
 * 
 *  This method tells us whether such a cast is needed.
 */
private boolean isToBeCastedAnyType(LightweightTypeReference actualType, XExpression obj, ITreeAppendable appendable) {
	if (actualType instanceof AnyTypeReference) {
		if (getReferenceName(obj, appendable) != null)
			return true;
		else if (obj instanceof XBlockExpression) {
			XBlockExpression blockExpression = (XBlockExpression) obj;
			EList<XExpression> expressions = blockExpression.getExpressions();
			if (expressions.isEmpty())
				return false;
			if (expressions.size() > 1)
				return true;
			XExpression last = expressions.get(0);
			return isToBeCastedAnyType(actualType, last, appendable);
		}
	}
	return false;
}
 
Example 2
Source File: EcoreGenericsUtil.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected static void addTypeParameterBindingsRecursively(EClass context, TypeBindingAcceptor bindingAcceptor) {
	for (EGenericType genericSuperType : context.getEGenericSuperTypes()) {
		EClassifier rawSuperType = genericSuperType.getEClassifier();
		EList<EGenericType> typeArguments = genericSuperType.getETypeArguments();
		EList<ETypeParameter> typeParameters = rawSuperType.getETypeParameters();
		if (typeArguments.size() != typeParameters.size()) {
			throw new IllegalStateException(
					"Number of typeArguments does not match number of typeParameters in EGenericType "
							+ genericSuperType);
		}
		for (int i = 0; i < typeArguments.size(); ++i) {
			bindingAcceptor.accept(typeParameters.get(i), typeArguments.get(i));
		}
		if (rawSuperType instanceof EClass) {
			addTypeParameterBindingsRecursively((EClass) rawSuperType, bindingAcceptor);
		}
	}
}
 
Example 3
Source File: AbstractDataAdapter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts ODA <code>Properties</code> to ROM public properties.
 * 
 * @param sourceHandle
 *            the data source handle
 */

protected void updateROMPublicProperties( Properties designProps,
		ReportElementHandle sourceHandle ) throws SemanticException
{
	if ( designProps == null )
		return;

	EList publicProps = designProps.getProperties( );
	for ( int i = 0; i < publicProps.size( ); i++ )
	{
		Property prop = (Property) publicProps.get( i );

		String propName = prop.getName( );
		String propValue = prop.getValue( );

		propValue = (String) PropertyValueValidationUtil.validateProperty(
				sourceHandle, propName, propValue );

		sourceHandle.getElement( ).setProperty( propName, propValue );
	}
}
 
Example 4
Source File: TypeReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) {
  if ((type == null)) {
    throw new NullPointerException("type");
  }
  final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
  reference.setType(type);
  for (final JvmTypeReference typeArg : typeArgs) {
    reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg));
  }
  if ((type instanceof JvmGenericType)) {
    final EList<JvmTypeParameter> list = ((JvmGenericType)type).getTypeParameters();
    if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) {
      String _identifier = ((JvmGenericType)type).getIdentifier();
      String _plus = ("The type " + _identifier);
      String _plus_1 = (_plus + " expects ");
      int _size = list.size();
      String _plus_2 = (_plus_1 + Integer.valueOf(_size));
      String _plus_3 = (_plus_2 + " type arguments, but was ");
      int _size_1 = reference.getArguments().size();
      String _plus_4 = (_plus_3 + Integer.valueOf(_size_1));
      String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number.");
      throw new IllegalArgumentException(_plus_5);
    }
  }
  return reference;
}
 
Example 5
Source File: InteractiveRenderer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void hideFill( Fill fill )
{

	if ( fill instanceof ColorDefinition )
	{
		( (ColorDefinition) fill ).setTransparency( 0 );
	}
	else if ( fill instanceof Gradient )
	{
		( (Gradient) fill ).setTransparency( 0 );
	}
	else if ( fill instanceof Image )
	{
		// FIXME can't hide image
	}
	else if ( fill instanceof MultipleFill )
	{
		EList<Fill> list = ( (MultipleFill) fill ).getFills( );
		for ( int i = 0; i < list.size( ); i++ )
		{
			hideFill( list.get( i ) );
		}
	}

}
 
Example 6
Source File: ChartWithAxesImpl.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IAxis[] getValueAxes( )
{
	Axis bAxis = (Axis) getChartWithAxes( ).getAxes( ).get( 0 );
	EList oAxes = bAxis.getAssociatedAxes( );
	IAxis[] valueAxes = new IAxis[oAxes.size( )];
	for ( int i = 0; i < valueAxes.length; i++ )
	{
		valueAxes[i] = new AxisImpl( (Axis) oAxes.get( i ) );
	}
	return valueAxes;
}
 
Example 7
Source File: JvmAnnotationReferencePrinter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String _internalToString(JvmAnnotationValue jvmAnnotationValue) {
	EStructuralFeature ref = jvmAnnotationValue.eClass().getEStructuralFeature("values");
	if (ref == null) {
		throw new IllegalStateException("Cannot find feature with name 'values' in " + jvmAnnotationValue);
	}

	EList<?> values = (EList<?>) jvmAnnotationValue.eGet(ref);
	if (values.size() > 1) {
		return values.stream().map((value) -> internalToString(value)).collect(Collectors.joining(", ", "#[", "]"));
	} else {
		return internalToString(values.get(0));
	}
}
 
Example 8
Source File: RadarSeriesUIProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected RadarSeries getDesignTimeSeries( SeriesDefinition sd )
{
	final EList<Series> el = sd.getSeries( );
	Series se;
	for ( int i = 0; i < el.size( ); i++ )
	{
		se = el.get( i );
		if ( se.getDataSet( ) == null && se instanceof RadarSeries)
		{
			return (RadarSeries) se;
		}
	}
	return null;
}
 
Example 9
Source File: DataSetParameterAdapter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets all driver-defined parameters.
 * 
 * @param designParams
 *            a list contains <code>ParameterDefinition</code> instance.
 * @param userDefinedList
 *            a list contains user-defined parameter. Each item is
 *            <code>OdaDataSetParameter</code>.
 * 
 * @return a list contains driver-defined parameter.Each item is copy of
 *         <code>ParameterDefinition</code>.
 * @throws SemanticException
 */

static DataSetParameters getDriverDefinedParameters( EList designParams,
		List userDefinedList ) throws SemanticException
{
	List<ParameterDefinition> resultList = new ArrayList<ParameterDefinition>( );
	List posList = getPositions( userDefinedList );

	for ( int i = 0; designParams != null && i < designParams.size( ); ++i )
	{
		ParameterDefinition definition = (ParameterDefinition) designParams
				.get( i );
		DataElementAttributes dataAttrs = definition.getAttributes( );
		if ( dataAttrs == null )
			continue;

		int pos = dataAttrs.getPosition( );

		if ( !posList.contains( Integer.valueOf( pos ) ) )
		{
			// driver -defined parameter

			resultList.add( EcoreUtil.copy( definition ) );
		}
	}

	DataSetParameters retParams = ODADesignFactory.getFactory( )
			.createDataSetParameters( );
	retParams.getParameterDefinitions( ).addAll( resultList );

	return retParams;

}
 
Example 10
Source File: IfcUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static AxisAlignedBoundingBox3D getBoundingBox3D(List<IfcCartesianPoint> points) throws GeometryException {
	AxisAlignedBoundingBox3D box3d = new AxisAlignedBoundingBox3D();
	for (IfcCartesianPoint ifcCartesianPoint : points) {
		EList<Double> coordinates = ifcCartesianPoint.getCoordinates();
		if (coordinates.size() < 2) {
			throw new GeometryException("Not enough dimensions (" + coordinates.size() + ") for 3D boundingbox");
		}
		box3d.process(coordinates);
	}
	return box3d;
}
 
Example 11
Source File: SeriesGroupingComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void setAggParameter( Text oSource )
{
	String text = oSource.getText( );
	int index = fAggParamtersTextWidgets.indexOf( oSource );
	EList<String> parameters = fGrouping.getAggregateParameters( );
	for ( int i = parameters.size( ); i < fAggParamtersTextWidgets.size( ); i++ )
	{
		parameters.add( null );
	}
	parameters.set( index, text );
}
 
Example 12
Source File: UnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public State(UnorderedGroup group) {
	frames = new Stack<Frame>();
	EList<AbstractElement> elements = group.getElements();
	alternatives = elements.size();
	mandatoryAlternatives = new boolean[alternatives];
	mandatoryAlternativeCount = 0;
	for(int i = 0; i < alternatives; i++) {
		boolean isMandatory = !GrammarUtil.isOptionalCardinality(elements.get(i));
		if (isMandatory) {
			mandatoryAlternatives[i] = true;
			mandatoryAlternativeCount++;
		}
	}
}
 
Example 13
Source File: MultipleHyperlinksComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void populateUIValues( MultiURLValues urlValues )
{
	// Clear old items.
	fListHyperlinks.removeAll( );
	fURLValuesMap.clear( );
	
	setURLValues( urlValues );
	if ( fMultiURLValues == null )
	{
		fMultiURLValues = MultiURLValuesImpl.create( );
	}

	EList<URLValue> urlValuies = fMultiURLValues.getURLValues( );
	String[] items = new String[urlValuies.size( )];
	int i = 0;
	for ( URLValue uv : urlValuies )
	{
		String text = uv.getLabel( ).getCaption( ).getValue( );
		if ( text == null )
		{
			text = uv.getBaseUrl( );
		}
		items[i] = text;
		fListHyperlinks.add( text );
		fURLValuesMap.put( text, uv );
		i++;
	}
	
	if ( fMultiURLValues.getTooltip( ) != null )
	{
		fTxtTooltip.setText(  fMultiURLValues.getTooltip( ) );
	}
	updateButtonStatus( );
}
 
Example 14
Source File: SeriesDefinitionImpl.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public final List<Series> getRunTimeSeries( )
{
	final List<Series> alRTS = new ArrayList<Series>( );
	final EList el = getSeries( );
	Series se;
	for ( int i = 0; i < el.size( ); i++ )
	{
		se = (Series) el.get( i );
		if ( se.getDataSet( ) != null )
		{
			alRTS.add( se );
		}
	}
	return alRTS;
}
 
Example 15
Source File: IfcUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static AxisAlignedBoundingBox2D getBoundingBox2D(List<IfcCartesianPoint> points) throws GeometryException {
	AxisAlignedBoundingBox2D box2d = new AxisAlignedBoundingBox2D();
	for (IfcCartesianPoint ifcCartesianPoint : points) {
		EList<Double> coordinates = ifcCartesianPoint.getCoordinates();
		if (coordinates.size() > 2) {
			throw new GeometryException("Too many dimensions (" + coordinates.size() + ") for 2D boundingbox");
		}
		box2d.process(coordinates);
	}
	return box2d;
}
 
Example 16
Source File: DefaultChartTypeImpl.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Vector<BaseSampleData> getConvertedBaseSampleDataRepresentation(
		EList<BaseSampleData> bsdList, AxisType xAxisType )
{
	Vector<BaseSampleData> vNewBaseSampleData = new Vector<BaseSampleData>( );
	for ( int i = 0; i < bsdList.size( ); i++ )
	{
		BaseSampleData bsd = bsdList.get( i );
		bsd.setDataSetRepresentation( ChartUIUtil.getConvertedSampleDataRepresentation( xAxisType,
				bsd.getDataSetRepresentation( ),
				i ) );
		vNewBaseSampleData.add( bsd );
	}
	return vNewBaseSampleData;
}
 
Example 17
Source File: ChartUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adjust data set if there are big number in chart model. In order to get
 * same scale in same axis, all big number in data sets in same axis will
 * have same divisor, this method computes same divisor for each axis in
 * chart model.
 * 
 * @param cm
 * @throws ChartException
 * @since 2.6
 */
public static void adjustBigNumberWithinDataSets(Chart cm ) throws ChartException
{
	if ( cm instanceof ChartWithAxes )
	{
		ChartWithAxes cwa = (ChartWithAxes) cm;
		final Axis axPrimaryBase = cwa.getPrimaryBaseAxes( )[0];
		
		adjustDataSets( cwa.getPrimaryBaseAxes( )[0] );

		final Axis[] axaOrthogonal = cwa.getOrthogonalAxes( axPrimaryBase,
				true );

		for ( int i = 0; i < axaOrthogonal.length; i++ ) // FOR EACH AXIS
		{
			adjustDataSets( axaOrthogonal[i] );
		}
	}
	else if ( cm instanceof ChartWithoutAxes )
	{
		ChartWithoutAxes cwoa = (ChartWithoutAxes) cm;
		
		EList<SeriesDefinition> elSD = cwoa.getSeriesDefinitions( );
		final SeriesDefinition sdBase = elSD.get( 0 );
		final Series seBaseRuntimeSeries = sdBase.getRunTimeSeries( ).get( 0 );
		adjustDataSets( new Series[]{
			seBaseRuntimeSeries
		}, null, null );
		
		elSD = sdBase.getSeriesDefinitions( );
		for ( int j = 0; j < elSD.size( ); j++ ) // FOR EACH ORTHOGONAL
		// SERIES DEFINITION
		{
			SeriesDefinition sdOrthogonal = elSD.get( j );
			adjustDataSets( sdOrthogonal.getRunTimeSeries( )
					.toArray( new Series[]{} ),
					null,
					null );
		}
	}
}
 
Example 18
Source File: DataProcessor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private GroupKey[] findGroupKeys( ChartWithAxes cwa,
		GroupingLookupHelper lhmLookup )
{
	final List<GroupKey> alKeys = new ArrayList<GroupKey>( 4 );

	final Axis axPrimaryBase = cwa.getPrimaryBaseAxes( )[0];

	// Find all orthogonal group keys in model
	final Axis[] axaOrthogonal = cwa.getOrthogonalAxes( axPrimaryBase, true );
	EList<SeriesDefinition> elSD;
	SeriesDefinition sd;
	Query qOrthogonalSeriesDefinition;
	String sExpression;

	for ( int i = 0; i < axaOrthogonal.length; i++ )
	{
		elSD = axaOrthogonal[i].getSeriesDefinitions( );

		for ( int j = 0; j < elSD.size( ); j++ )
		{
			sd = elSD.get( j );
			qOrthogonalSeriesDefinition = sd.getQuery( );
			if ( qOrthogonalSeriesDefinition == null )
			{
				continue;
			}

			sExpression = qOrthogonalSeriesDefinition.getDefinition( );
			if ( sExpression != null && sExpression.trim( ).length( ) > 0 )
			{
				GroupKey sortKey = new GroupKey( sExpression,
						sd.isSetSorting( ) ? sd.getSorting( ) : null );
				if ( !alKeys.contains( sortKey ) )
				{
					sortKey.setKeyIndex( lhmLookup.findIndex( sExpression,
							lhmLookup.getOrthogonalAggregationExpression( sd ) ) );
					alKeys.add( sortKey );
				}
			}
		}
	}

	return alKeys.toArray( new GroupKey[alKeys.size( )] );
}
 
Example 19
Source File: AdapterUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Updates values in ScalarValueChoices to the given report parameter.
 * 
 * @param staticChoices
 *            the latest scalar values
 * @param cachedChoices
 *            the cached scalar value
 * @param paramHandle
 *            the report parameter
 * @throws SemanticException
 */

static void updateROMSelectionList( ScalarValueChoices staticChoices,
		ScalarValueChoices cachedChoices,
		AbstractScalarParameterHandle paramHandle )
		throws SemanticException
{
	if ( staticChoices == null || paramHandle == null )
		return;

	List retList = new ArrayList( );

	EList choiceList = staticChoices.getScalarValues( );
	EList cachedChoiceList = null;

	if ( cachedChoices != null )
		cachedChoiceList = cachedChoices.getScalarValues( );

	boolean useCached = false;
	if ( cachedChoiceList != null
			&& choiceList.size( ) == cachedChoiceList.size( ) )
		useCached = true;

	for ( int i = 0; i < choiceList.size( ); i++ )
	{
		ScalarValueDefinition valueDefn = (ScalarValueDefinition) choiceList
				.get( i );

		SelectionChoice choice = StructureFactory.createSelectionChoice( );
		choice.setValue( valueDefn.getValue( ) );

		String label = valueDefn.getDisplayName( );
		String labelKey = valueDefn.getDisplayNameKey( );

		if ( label != null || labelKey != null )
		{
			choice.setLabel( label );
			choice.setLabelResourceKey( labelKey );
		}
		else if ( useCached )
		{
			// use cached values

			valueDefn = (ScalarValueDefinition) cachedChoiceList.get( i );
			label = valueDefn.getDisplayName( );
			labelKey = valueDefn.getDisplayNameKey( );

			if ( label != null || labelKey != null )
			{
				choice.setLabel( label );
				choice.setLabelResourceKey( labelKey );
			}
		}

		retList.add( choice );
	}

	PropertyHandle propHandle = paramHandle
			.getPropertyHandle( AbstractScalarParameterHandle.SELECTION_LIST_PROP );

	propHandle.clearValue( );

	for ( int i = 0; i < retList.size( ); i++ )
	{
		propHandle.addItem( retList.get( i ) );
	}
}
 
Example 20
Source File: BrickLayout.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private static void seperateBuilding(final Building b) {
		// Don't build up bricks, if this building isn't visualized or isn't positioned (e.g. is an inner classes)
		if (b.getPosition() == null) {
			return;
		}

		// variables for brick algorithm
		int sc, 	// side capacity
			lc,		// layer capacity
			biws,	// brick index within side
			biwl,	// brick index within layer
			si,		// side index - north,east,...
			bsPosIndex_X, bsPosIndex_Y, bsPosIndex_Z;
		double b_lowerLeftX, b_upperY, b_lowerLeftZ;
		sc = b.getSideCapacity();

		// Get elements for modeling
		EList<BuildingSegment> classElements = new BasicEList<BuildingSegment>();
		switch (config.getClassElementsMode()) {
			case ATTRIBUTES_ONLY:
				classElements.addAll(b.getData());
				break;
			case METHODS_ONLY:
				classElements.addAll(b.getMethods());
				break;
			case METHODS_AND_ATTRIBUTES:
				classElements.addAll(b.getData());
				classElements.addAll(b.getMethods());
				break;
			default:
				classElements.addAll(b.getMethods());
				break;
		}

		// Sorting elements
		CityUtils.sortBuildingSegments(classElements);
		
		// coordinates of edges of building
		b_lowerLeftX = b.getPosition().getX() - b.getWidth()/2;
		b_lowerLeftZ = b.getPosition().getZ() - b.getLength()/2;
		b_upperY = b.getPosition().getY() + b.getHeight()/2;
//System.out.println("");
		BuildingSegment bs;
		// set positions for all methods in current class
		for(int i=0; i<classElements.size(); ++i) {
			bs = classElements.get(i);
			if(sc <= 1) {
				lc = 1;
				biws = 0;
				si = 0;
			} else {
				lc = (sc-1) * 4;
				biwl = i % lc;
				biws = biwl % (sc-1);
				si = biwl / (sc-1);
			}
//			System.out.println(bs.getType() + " " + bs.getValue() + " " + bs.getModifiers() + " " + bs.getNumberOfStatements());
			// calculating position for brick
			switch(si) {
				case 0:
					bsPosIndex_X = biws;
					bsPosIndex_Z = 0;
					break;
				case 1:
					bsPosIndex_X = sc - 1;
					bsPosIndex_Z = biws;
					break;
				case 2:
					bsPosIndex_X = sc - biws - 1;
					bsPosIndex_Z = sc - 1;
					break;
				default:
					bsPosIndex_X = 0;
					bsPosIndex_Z = sc - biws - 1;
					break;
			}
			bsPosIndex_Y = i / lc;

			// setting position for brick
			Position pos = cityFactory.createPosition();
			pos.setX(b_lowerLeftX + config.getBrickHorizontalMargin()
					+ (config.getBrickHorizontalGap() + config.getBrickSize()) * bsPosIndex_X
					+ config.getBrickSize() * 0.5);
			pos.setZ(b_lowerLeftZ + config.getBrickHorizontalMargin()
					+ (config.getBrickHorizontalGap() + config.getBrickSize()) * bsPosIndex_Z
					+ config.getBrickSize() * 0.5);
			pos.setY(b_upperY + config.getBrickVerticalMargin()
					+ (config.getBrickVerticalGap() + config.getBrickSize()) * bsPosIndex_Y
					+ config.getBrickSize() * 0.5);
			bs.setPosition(pos);
		}
	}