Example usage for org.apache.commons.collections CollectionUtils size

List of usage examples for org.apache.commons.collections CollectionUtils size

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils size.

Prototype

public static int size(Object object) 

Source Link

Document

Gets the size of the collection/iterator specified.

Usage

From source file:org.goko.tools.viewer.jogl.utils.render.GridRenderer.java

private void buildGrid() throws GkException {
    buildMatrix();//from  ww w.j  a  v a 2s .  c om
    List<Point4d> lstVertices = new ArrayList<Point4d>();
    List<Color4f> lstColors = new ArrayList<Color4f>();

    Tuple6b lclStart6b = new Tuple6b();
    lclStart6b.min(start, end);
    Tuple6b lclEnd6b = new Tuple6b();
    lclEnd6b.max(start, end);
    Tuple6b lclCenter6b = new Tuple6b(0, 0, 0, JoglUtils.JOGL_UNIT);
    if (gcodeContextProvider != null) {
        GCodeContext context = gcodeContextProvider.getGCodeContext();
        lclCenter6b = context.getCoordinateSystemData(context.getCoordinateSystem());
    }
    // Determine min/max if zero is not in the desired area
    lclCenter6b = lclCenter6b.max(lclStart6b).min(lclEnd6b);

    Point3f lclStart = lclStart6b.toPoint3f(JoglUtils.JOGL_UNIT);
    axisTransformMatrix.transform(lclStart);
    Point3f lclEnd = lclEnd6b.toPoint3f(JoglUtils.JOGL_UNIT);
    axisTransformMatrix.transform(lclEnd);
    Point3f lclCenter = lclCenter6b.toPoint3f(JoglUtils.JOGL_UNIT);
    axisTransformMatrix.transform(lclCenter);
    Matrix4d invAxisTransformMatrix = new Matrix4d(axisTransformMatrix);
    invAxisTransformMatrix.invert();

    addVertice(new Point4d(lclCenter.x, lclStart.y, lclCenter.z, 1), lstVertices, invAxisTransformMatrix);
    addVertice(new Point4d(lclCenter.x, lclEnd.y, lclCenter.z, 1), lstVertices, invAxisTransformMatrix);
    addVertice(new Point4d(lclStart.x, lclCenter.y, lclCenter.z, 1), lstVertices, invAxisTransformMatrix);
    addVertice(new Point4d(lclEnd.x, lclCenter.y, lclCenter.z, 1), lstVertices, invAxisTransformMatrix);
    lstColors.add(originColor);
    lstColors.add(originColor);
    lstColors.add(originColor);
    lstColors.add(originColor);

    Tuple6b deltaPlus = lclEnd6b.subtract(lclCenter6b).max(new Tuple6b(0, 0, 0, JoglUtils.JOGL_UNIT));
    Tuple6b deltaMinus = lclCenter6b.subtract(lclStart6b).max(new Tuple6b(0, 0, 0, JoglUtils.JOGL_UNIT));

    // Major divisions
    int nbStepXPlusMajor = Math.abs(deltaPlus.getX().divide(majorIncrement).intValue());
    int nbStepYPlusMajor = Math.abs(deltaPlus.getY().divide(majorIncrement).intValue());
    int nbStepZPlusMajor = Math.abs(deltaPlus.getZ().divide(majorIncrement).intValue());

    int nbStepXMinusMajor = Math.abs(deltaMinus.getX().divide(majorIncrement).intValue());
    int nbStepYMinusMajor = Math.abs(deltaMinus.getY().divide(majorIncrement).intValue());
    int nbStepZMinusMajor = Math.abs(deltaMinus.getZ().divide(majorIncrement).intValue());

    Vector3f nbStepPlusMajor = new Vector3f(nbStepXPlusMajor, nbStepYPlusMajor, nbStepZPlusMajor);
    Vector3f nbStepMinusMajor = new Vector3f(nbStepXMinusMajor, nbStepYMinusMajor, nbStepZMinusMajor);
    axisTransformMatrix.transform(nbStepPlusMajor);
    axisTransformMatrix.transform(nbStepMinusMajor);

    double majorIncrementJoglUnit = majorIncrement.doubleValue(JoglUtils.JOGL_UNIT);
    double minorIncrementJoglUnit = minorIncrement.doubleValue(JoglUtils.JOGL_UNIT);
    for (int i = 1; i <= nbStepPlusMajor.x; i++) {
        addVertice(new Point4d(lclCenter.x + i * majorIncrementJoglUnit, lclStart.y, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclCenter.x + i * majorIncrementJoglUnit, lclEnd.y, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);

        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
    }

    for (int i = 1; i <= nbStepMinusMajor.x; i++) {
        addVertice(new Point4d(lclCenter.x - i * majorIncrementJoglUnit, lclStart.y, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclCenter.x - i * majorIncrementJoglUnit, lclEnd.y, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
    }

    for (int i = 1; i <= nbStepPlusMajor.y; i++) {
        addVertice(new Point4d(lclStart.x, lclCenter.y + i * majorIncrementJoglUnit, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclEnd.x, lclCenter.y + i * majorIncrementJoglUnit, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
    }

    for (int i = 1; i <= nbStepMinusMajor.y; i++) {
        addVertice(new Point4d(lclStart.x, lclCenter.y - i * majorIncrementJoglUnit, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclEnd.x, lclCenter.y - i * majorIncrementJoglUnit, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
    }

    // Minor divisions
    int nbStepXPlusMinor = Math.abs(deltaPlus.getX().divide(minorIncrement).intValue());
    int nbStepYPlusMinor = Math.abs(deltaPlus.getY().divide(minorIncrement).intValue());
    int nbStepZPlusMinor = Math.abs(deltaPlus.getZ().divide(minorIncrement).intValue());

    int nbStepXMinusMinor = Math.abs(deltaMinus.getX().divide(minorIncrement).intValue());
    int nbStepYMinusMinor = Math.abs(deltaMinus.getY().divide(minorIncrement).intValue());
    int nbStepZMinusMinor = Math.abs(deltaMinus.getZ().divide(minorIncrement).intValue());

    Vector3f nbStepPlusMinor = new Vector3f(nbStepXPlusMinor, nbStepYPlusMinor, nbStepZPlusMinor);
    Vector3f nbStepMinusMinor = new Vector3f(nbStepXMinusMinor, nbStepYMinusMinor, nbStepZMinusMinor);

    axisTransformMatrix.transform(nbStepPlusMinor);
    axisTransformMatrix.transform(nbStepMinusMinor);

    for (int i = 1; i <= nbStepPlusMinor.x; i++) {
        addVertice(new Point4d(lclCenter.x + i * minorIncrementJoglUnit, lclStart.y, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclCenter.x + i * minorIncrementJoglUnit, lclEnd.y, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(minorUnitColor);
        lstColors.add(minorUnitColor);
    }

    for (int i = 1; i <= nbStepMinusMinor.x; i++) {
        addVertice(new Point4d(lclCenter.x - i * minorIncrementJoglUnit, lclStart.y, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclCenter.x - i * minorIncrementJoglUnit, lclEnd.y, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(minorUnitColor);
        lstColors.add(minorUnitColor);
    }

    for (int i = 1; i <= nbStepPlusMinor.y; i++) {
        addVertice(new Point4d(lclStart.x, lclCenter.y + i * minorIncrementJoglUnit, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclEnd.x, lclCenter.y + i * minorIncrementJoglUnit, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(minorUnitColor);
        lstColors.add(minorUnitColor);
    }

    for (int i = 1; i <= nbStepMinusMinor.y; i++) {
        addVertice(new Point4d(lclStart.x, lclCenter.y - i * minorIncrementJoglUnit, lclCenter.z, 1),
                lstVertices, invAxisTransformMatrix);
        addVertice(new Point4d(lclEnd.x, lclCenter.y - i * minorIncrementJoglUnit, lclCenter.z, 1), lstVertices,
                invAxisTransformMatrix);
        lstColors.add(minorUnitColor);
        lstColors.add(minorUnitColor);
    }

    // Add X Zero red axis
    if (normal.dot(new Vector4f(1, 0, 0, 0)) == 0) {
        addVertice(new Point4d(lclStart.x, 0, 0, 1), lstVertices, null);
        addVertice(new Point4d(lclEnd.x, 0, 0, 1), lstVertices, null);
        lstColors.add(new Color4f(1, 0, 0, axisOpacity));
        lstColors.add(new Color4f(1, 0, 0, axisOpacity));
    }

    // Add Y Zero green axis
    if (normal.dot(new Vector4f(0, 1, 0, 0)) == 0) {
        addVertice(new Point4d(0, lclStart.y, 0, 1), lstVertices, null);
        addVertice(new Point4d(0, lclEnd.y, 0, 1), lstVertices, null);
        lstColors.add(new Color4f(0, 1, 0, axisOpacity));
        lstColors.add(new Color4f(0, 1, 0, axisOpacity));
    }

    // Add Z Zero Blue axis
    if (normal.dot(new Vector4f(0, 0, 1, 0)) == 0) {
        addVertice(new Point4d(0, 0, lclStart.z, 1), lstVertices, null);
        addVertice(new Point4d(0, 0, lclEnd.z, 1), lstVertices, null);
        lstColors.add(new Color4f(0, 0, 1, axisOpacity));
        lstColors.add(new Color4f(0, 0, 1, axisOpacity));
    }
    setVerticesCount(CollectionUtils.size(lstVertices));
    setColorsBuffer(JoglUtils.buildFloatBuffer4f(lstColors));
    setVerticesBuffer(JoglUtils.buildFloatBuffer4d(lstVertices));
}

From source file:org.goko.viewer.jogl.utils.render.gcode.DefaultGCodeProviderRenderer.java

/** (inheritDoc)
 * @see org.goko.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer#buildGeometry()
 *//*from  w w  w .j a v  a2  s  .co  m*/
@Override
protected void buildGeometry() throws GkException {
    List<GCodeCommand> commands = gcodeProvider.getGCodeCommands();
    ArrayList<Point3d> lstVertices = new ArrayList<Point3d>();
    ArrayList<Color4f> lstColors = new ArrayList<Color4f>();
    mapVerticesPositionByIdCommand = new HashMap<Integer, Integer[]>();
    boolean firstCommand = true;
    for (GCodeCommand command : commands) {
        List<Point3d> lstCmdVertices = generator.generateVertices(command);
        if (CollectionUtils.isNotEmpty(lstCmdVertices)) {
            if (firstCommand) {
                firstCommand = false;
            } else {
                lstCmdVertices.remove(0);
            }
            // First index is the position of the first vertices that belong to the command
            // Second index is the number of vertices that belongs to this command
            if (CollectionUtils.isNotEmpty(lstCmdVertices)) {
                mapVerticesPositionByIdCommand.put(command.getId(),
                        new Integer[] { lstVertices.size(), lstCmdVertices.size() });
                lstVertices.addAll(lstCmdVertices);
            }
            // Let's generate the colors
            Color4f color = colorizer.getColor(command);
            for (Point3d point3d : lstCmdVertices) {
                lstColors.add(color);
            }
        }
    }
    setVerticesCount(CollectionUtils.size(lstVertices));
    stateBuffer = IntBuffer.allocate(getVerticesCount());
    stateBuffer.rewind();
    //generateCommandStateBuffer();
    setColorsBuffer(JoglUtils.buildFloatBuffer4f(lstColors));
    setVerticesBuffer(JoglUtils.buildFloatBuffer3d(lstVertices));
}

From source file:org.goko.viewer.jogl.utils.render.GridRenderer.java

private void buildGrid() throws GkException {
    Unit<Length> unit = GokoPreference.getInstance().getLengthUnit();
    Quantity<Length> majorQuantity = NumberQuantity
            .of(JoglViewerPreference.getInstance().getMajorGridSpacing().doubleValue(), unit);
    Quantity<Length> minorQuantity = NumberQuantity
            .of(JoglViewerPreference.getInstance().getMinorGridSpacing().doubleValue(), unit);
    majorUnit = majorQuantity.to(SIPrefix.MILLI(SI.METRE)).doubleValue();
    minorUnit = minorQuantity.to(SIPrefix.MILLI(SI.METRE)).doubleValue();
    size = 10 * majorUnit;/*from w  ww.  j a v  a2  s  .co  m*/
    List<Point4d> lstVertices = new ArrayList<Point4d>();
    List<Point4d> lstColors = new ArrayList<Point4d>();

    // Origin
    lstVertices.add(new Point4d(0, -size, 0, 1));
    lstVertices.add(new Point4d(0, size, 0, 1));
    lstVertices.add(new Point4d(-size, 0, 0, 1));
    lstVertices.add(new Point4d(size, 0, 0, 1));
    lstColors.add(originColor);
    lstColors.add(originColor);
    lstColors.add(originColor);
    lstColors.add(originColor);

    // Main divisions
    for (double i = -size; i <= size; i += majorUnit) {
        lstVertices.add(new Point4d(i, -size, 0, 1));
        lstVertices.add(new Point4d(i, size, 0, 1));
        lstVertices.add(new Point4d(-size, i, 0, 1));
        lstVertices.add(new Point4d(size, i, 0, 1));
        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
        lstColors.add(majorUnitColor);
    }

    // Subdivisions
    for (double i = -size; i <= size; i += minorUnit) {
        if (i != 0 && Math.abs(i % majorUnit) >= 0.01) {
            lstVertices.add(new Point4d(i, -size, 0, 1));
            lstVertices.add(new Point4d(i, size, 0, 1));
            lstVertices.add(new Point4d(-size, i, 0, 1));
            lstVertices.add(new Point4d(size, i, 0, 1));
            lstColors.add(minorUnitColor);
            lstColors.add(minorUnitColor);
            lstColors.add(minorUnitColor);
            lstColors.add(minorUnitColor);
        }
    }
    setVerticesCount(CollectionUtils.size(lstVertices));
    setColorsBuffer(JoglUtils.buildFloatBuffer4d(lstColors));
    setVerticesBuffer(JoglUtils.buildFloatBuffer4d(lstVertices));
}

From source file:org.gravidence.gravifon.db.domain.ChartDocument.java

/**
 * Adds an item to the document.<p>
 * {@link #getItems() Items} are always sorted by {@link ChartItem} comparator rules.
 * // ww w  .j  a  v a  2 s.  co  m
 * @param id chart item entity primary variation identifier
 * @param title chart item entity title
 * @param value chart item entity calculated value (amount or duration)
 */
public void addItem(String id, String title, BigInteger value) {
    if (items == null) {
        items = new ArrayList<>(size + 1);
    }

    if (CollectionUtils.size(items) < size) {
        items.add(new ChartItem(id, title, value));
    } else if (ObjectUtils.compare(value, items.get(items.size() - 1).getValue()) > 0) {
        items.remove(items.size() - 1);

        items.add(new ChartItem(id, title, value));

        Collections.sort(items);
    }
}

From source file:org.gravidence.gravifon.resource.bean.ValidateableBean.java

/**
 * Checks that field length satisfies specified range (inclusive).
 * /* www .  j  a  v  a  2  s. co  m*/
 * @param fieldValue field value
 * @param fieldName field name to use in error message
 * @param min minimum number of elements expected
 * @param max maximum number of elements expected
 * @throws ValidationException in case field length is invalid
 */
public static void checkLength(List fieldValue, String fieldName, int min, int max) {
    int fieldLength = CollectionUtils.size(fieldValue);
    if (fieldLength < min || fieldLength > max) {
        throw new ValidationException(GravifonError.INVALID,
                String.format("Property '%s' value length is out of expected range.", fieldName));
    }
}

From source file:org.itracker.core.resources.ITrackerResources.java

public static ResourceBundle getBundle(Locale locale) {
    if (locale == null) {
        locale = getLocale();/*from  w ww  . j  av a  2s.c o  m*/
    }

    ResourceBundle bundle = languages.get(locale);
    if (bundle == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("getBundle: Loading new resource bundle for locale " + locale + " from the database.");
        }
        if (!isInitialized()) {
            return ITrackerResourceBundle.loadBundle(locale);
        } else {

            Properties languageItems = configurationService.getLanguageProperties(locale);

            logger.info("lazy loading locale bundle resources: {}", locale);

            bundle = ITrackerResourceBundle.loadBundle(locale, languageItems);
            logger.info("getBundle: got loaded for locale {} with {} items from the database.", locale,
                    null == languageItems ? "no" : CollectionUtils.size(languageItems));
            logger.debug("getBundle: got loaded for locale {} with items {} from the database.", locale,
                    languageItems);

            putBundle(locale, bundle);
        }

    }

    return bundle;
}

From source file:org.jspringbot.keyword.csv.CSVState.java

public void parseCSVString(String csv) throws IOException {
    readAll(new StringReader(csv));

    LOG.createAppender().appendBold("Parse CSV String:").append(" (count=%d)", CollectionUtils.size(lines))
            .appendText(toCSV(lines)).log();
}

From source file:org.jspringbot.keyword.csv.CSVState.java

public void parseCSVResource(String resource) throws IOException {
    ResourceEditor editor = new ResourceEditor();
    editor.setAsText(resource);//  www .  j ava 2  s.  co  m

    Resource r = (Resource) editor.getValue();

    readAll(new InputStreamReader(r.getInputStream()));

    LOG.createAppender().appendBold("Parse CSV Resource:").append(" (count=%d)", CollectionUtils.size(lines))
            .appendText(toCSV(lines)).log();
}

From source file:org.jspringbot.keyword.test.data.TestData.java

public int getSize() {
    return CollectionUtils.size(contents);
}

From source file:org.kuali.rice.kim.impl.role.RoleServiceBase.java

protected String getKimAttributeId(String kimTypeId, String attributeName) {
    Collection<KimAttributeBo> attributeData = getAttributeByName(attributeName);
    String kimAttributeId = null;

    if (CollectionUtils.isNotEmpty(attributeData)) {
        if (CollectionUtils.size(attributeData) == 1) {
            kimAttributeId = attributeData.iterator().next().getId();
        } else {//from  w ww.ja  va  2  s.  c o m
            kimAttributeId = getCorrectAttributeId(kimTypeId, attributeName, attributeData);
        }
    }

    return kimAttributeId;
}