Example usage for java.lang Integer MIN_VALUE

List of usage examples for java.lang Integer MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Integer MIN_VALUE.

Prototype

int MIN_VALUE

To view the source code for java.lang Integer MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value an int can have, -231.

Usage

From source file:LongVector.java

/**
 * Searches for the first occurence of the given argument, beginning the
 * search at index, and testing for equality using the equals method.
 * /*from w ww . ja v  a 2  s .co m*/
 * @param elem
 *            object to look for
 * @param index
 *            Index of where to begin search
 * @return the index of the first occurrence of the object argument in this
 *         vector at position index or later in the vector; returns -1 if
 *         the object is not found.
 */
public final int indexOf(long elem, int index) {

    for (int i = index; i < _size; i++) {
        if (_data[i] == elem)
            return i;
    }

    return java.lang.Integer.MIN_VALUE;
}

From source file:br.com.fidias.chance4j.Chance.java

/**
 * Return a random integer between {@value Integer#MIN_VALUE} and
 * {@value Integer#MAX_VALUE}./*  w  ww.jav a  2 s .  co m*/
 * <pre>
 * chance.integer();
 * => 4529
 * chance.integer();
 * => -908
 * </pre>
 *
 * @return A single random integer number
 * @throws ChanceException
 */
public int integer() throws ChanceException {
    return integer(Integer.MIN_VALUE, Integer.MAX_VALUE);
}

From source file:com.baidu.oped.apm.common.buffer.AutomaticBufferTest.java

@Test
public void testPutVarInt() throws Exception {
    Buffer buffer = new AutomaticBuffer(0);
    buffer.putVar(Integer.MAX_VALUE);
    buffer.putVar(Integer.MIN_VALUE);
    buffer.putVar(0);//from w  w w  .ja v  a 2 s  . co m
    buffer.putVar(1);
    buffer.putVar(12345);

    buffer.setOffset(0);
    Assert.assertEquals(buffer.readVarInt(), Integer.MAX_VALUE);
    Assert.assertEquals(buffer.readVarInt(), Integer.MIN_VALUE);
    Assert.assertEquals(buffer.readVarInt(), 0);
    Assert.assertEquals(buffer.readVarInt(), 1);
    Assert.assertEquals(buffer.readVarInt(), 12345);
}

From source file:IntVector.java

/**
 * Searches for the first occurence of the given argument, beginning the
 * search at index, and testing for equality using the equals method.
 * //from  w w  w.j a va2  s.c  om
 * @param elem
 *            object to look for
 * @param index
 *            Index of where to begin search
 * @return the index of the first occurrence of the object argument in this
 *         vector at position index or later in the vector; returns -1 if
 *         the object is not found.
 */
public final int indexOf(int elem, int index) {

    for (int i = index; i < _size; i++) {
        if (_data[i] == elem)
            return i;
    }

    return java.lang.Integer.MIN_VALUE;
}

From source file:com.juanojfp.gcmsample.MainActivity.java

/**
 * Gets the current registration id for application on GCM service.
 * <p>/*  ww w  .j  a v a 2  s  .co m*/
 * If result is empty, the registration has failed.
 *
 * @return registration id, or empty string if the registration is not
 *         complete.
 */
private String getRegistrationId(Context context) {
    final SharedPreferences prefs = getGCMPreferences(context);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.length() == 0) {
        Log.v(TAG, "Registration not found.");
        return "";
    }
    // check if app was updated; if so, it must clear registration id to
    // avoid a race condition if GCM sends a message
    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion(context);
    if (registeredVersion != currentVersion || isRegistrationExpired()) {
        Log.v(TAG, "App version changed or registration expired.");
        return "";
    }
    return registrationId;
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorFactory.java

/**
 * Returns the result set process for the given select expression, group-by clause and
 * having clause given a set of types describing each stream in the from-clause.
 * @param statementSpecCompiled - the statement specification
 * @param stmtContext - engine and statement level services
 * @param typeService - for information about the streams in the from clause
 * @param viewResourceDelegate - delegates views resource factory to expression resources requirements
 * @param isUnidirectionalStream - true if unidirectional join for any of the streams
 * @param allowAggregation - indicator whether to allow aggregation functions in any expressions
 * @return result set processor instance
 * @throws ExprValidationException when any of the expressions is invalid
 *//*from   w  w  w . java 2  s . c  o m*/
public static ResultSetProcessor getProcessor(StatementSpecCompiled statementSpecCompiled,
        StatementContext stmtContext, StreamTypeService typeService, ViewResourceDelegate viewResourceDelegate,
        boolean[] isUnidirectionalStream, boolean allowAggregation) throws ExprValidationException {
    SelectClauseSpecCompiled selectClauseSpec = statementSpecCompiled.getSelectClauseSpec();
    InsertIntoDesc insertIntoDesc = statementSpecCompiled.getInsertIntoDesc();
    List<ExprNode> groupByNodes = statementSpecCompiled.getGroupByExpressions();
    ExprNode optionalHavingNode = statementSpecCompiled.getHavingExprRootNode();
    OutputLimitSpec outputLimitSpec = statementSpecCompiled.getOutputLimitSpec();
    List<OrderByItem> orderByList = statementSpecCompiled.getOrderByList();

    if (log.isDebugEnabled()) {
        log.debug(".getProcessor Getting processor for " + " selectionList="
                + selectClauseSpec.getSelectExprList() + " groupByNodes="
                + Arrays.toString(groupByNodes.toArray()) + " optionalHavingNode=" + optionalHavingNode);
    }

    boolean isUnidirectional = false;
    for (int i = 0; i < isUnidirectionalStream.length; i++) {
        isUnidirectional |= isUnidirectionalStream[i];
    }

    // Expand any instances of select-clause names in the
    // order-by clause with the full expression
    expandColumnNames(selectClauseSpec.getSelectExprList(), orderByList);

    // Validate selection expressions, if any (could be wildcard i.e. empty list)
    List<SelectClauseExprCompiledSpec> namedSelectionList = new LinkedList<SelectClauseExprCompiledSpec>();
    ExprValidationContext validationContext = new ExprValidationContext(typeService,
            stmtContext.getMethodResolutionService(), viewResourceDelegate, stmtContext.getSchedulingService(),
            stmtContext.getVariableService(), stmtContext, stmtContext.getEventAdapterService(),
            stmtContext.getStatementName(), stmtContext.getStatementId(), stmtContext.getAnnotations());
    for (int i = 0; i < selectClauseSpec.getSelectExprList().size(); i++) {
        // validate element
        SelectClauseElementCompiled element = selectClauseSpec.getSelectExprList().get(i);
        if (element instanceof SelectClauseExprCompiledSpec) {
            SelectClauseExprCompiledSpec expr = (SelectClauseExprCompiledSpec) element;
            ExprNode validatedExpression = ExprNodeUtility.getValidatedSubtree(expr.getSelectExpression(),
                    validationContext);

            // determine an element name if none assigned
            String asName = expr.getAssignedName();
            if (asName == null) {
                asName = validatedExpression.toExpressionString();
            }

            expr.setAssignedName(asName);
            expr.setSelectExpression(validatedExpression);
            namedSelectionList.add(expr);
        }
    }
    boolean isUsingWildcard = selectClauseSpec.isUsingWildcard();

    // Validate stream selections, if any (such as stream.*)
    boolean isUsingStreamSelect = false;
    for (SelectClauseElementCompiled compiled : selectClauseSpec.getSelectExprList()) {
        if (!(compiled instanceof SelectClauseStreamCompiledSpec)) {
            continue;
        }
        SelectClauseStreamCompiledSpec streamSelectSpec = (SelectClauseStreamCompiledSpec) compiled;
        int streamNum = Integer.MIN_VALUE;
        boolean isFragmentEvent = false;
        boolean isProperty = false;
        Class propertyType = null;
        isUsingStreamSelect = true;
        for (int i = 0; i < typeService.getStreamNames().length; i++) {
            String streamName = streamSelectSpec.getStreamName();
            if (typeService.getStreamNames()[i].equals(streamName)) {
                streamNum = i;
                break;
            }

            // see if the stream name is known as a nested event type
            EventType candidateProviderOfFragments = typeService.getEventTypes()[i];
            // for the native event type we don't need to fragment, we simply use the property itself since all wrappers understand Java objects
            if (!(candidateProviderOfFragments instanceof NativeEventType)
                    && (candidateProviderOfFragments.getFragmentType(streamName) != null)) {
                streamNum = i;
                isFragmentEvent = true;
                break;
            }
        }

        // stream name not found
        if (streamNum == Integer.MIN_VALUE) {
            // see if the stream name specified resolves as a property
            PropertyResolutionDescriptor desc = null;
            try {
                desc = typeService.resolveByPropertyName(streamSelectSpec.getStreamName());
            } catch (StreamTypesException e) {
                // not handled
            }

            if (desc == null) {
                throw new ExprValidationException("Stream selector '" + streamSelectSpec.getStreamName()
                        + ".*' does not match any stream name in the from clause");
            }
            isProperty = true;
            propertyType = desc.getPropertyType();
            streamNum = desc.getStreamNum();
        }

        streamSelectSpec.setStreamNumber(streamNum);
        streamSelectSpec.setFragmentEvent(isFragmentEvent);
        streamSelectSpec.setProperty(isProperty, propertyType);
    }

    // Validate group-by expressions, if any (could be empty list for no group-by)
    Class[] groupByTypes = new Class[groupByNodes.size()];
    for (int i = 0; i < groupByNodes.size(); i++) {
        // Ensure there is no subselects
        ExprNodeSubselectVisitor visitor = new ExprNodeSubselectVisitor();
        groupByNodes.get(i).accept(visitor);
        if (visitor.getSubselects().size() > 0) {
            throw new ExprValidationException("Subselects not allowed within group-by");
        }

        ExprNode validatedGroupBy = ExprNodeUtility.getValidatedSubtree(groupByNodes.get(i), validationContext);
        groupByNodes.set(i, validatedGroupBy);
        groupByTypes[i] = validatedGroupBy.getExprEvaluator().getType();
    }
    stmtContext.getMethodResolutionService().setGroupKeyTypes(groupByTypes);

    // Validate having clause, if present
    if (optionalHavingNode != null) {
        // Ensure there is no subselects
        ExprNodeSubselectVisitor visitor = new ExprNodeSubselectVisitor();
        optionalHavingNode.accept(visitor);
        if (visitor.getSubselects().size() > 0) {
            throw new ExprValidationException("Subselects not allowed within having-clause");
        }

        optionalHavingNode = ExprNodeUtility.getValidatedSubtree(optionalHavingNode, validationContext);
    }

    // Validate order-by expressions, if any (could be empty list for no order-by)
    for (int i = 0; i < orderByList.size(); i++) {
        ExprNode orderByNode = orderByList.get(i).getExprNode();

        // Ensure there is no subselects
        ExprNodeSubselectVisitor visitor = new ExprNodeSubselectVisitor();
        orderByNode.accept(visitor);
        if (visitor.getSubselects().size() > 0) {
            throw new ExprValidationException("Subselects not allowed within order-by clause");
        }

        Boolean isDescending = orderByList.get(i).isDescending();
        OrderByItem validatedOrderBy = new OrderByItem(
                ExprNodeUtility.getValidatedSubtree(orderByNode, validationContext), isDescending);
        orderByList.set(i, validatedOrderBy);
    }

    // Get the select expression nodes
    List<ExprNode> selectNodes = new ArrayList<ExprNode>();
    for (SelectClauseExprCompiledSpec element : namedSelectionList) {
        selectNodes.add(element.getSelectExpression());
    }

    // Get the order-by expression nodes
    List<ExprNode> orderByNodes = new ArrayList<ExprNode>();
    for (OrderByItem element : orderByList) {
        orderByNodes.add(element.getExprNode());
    }

    // Determine aggregate functions used in select, if any
    List<ExprAggregateNode> selectAggregateExprNodes = new LinkedList<ExprAggregateNode>();
    for (SelectClauseExprCompiledSpec element : namedSelectionList) {
        ExprAggregateNodeUtil.getAggregatesBottomUp(element.getSelectExpression(), selectAggregateExprNodes);
    }
    if (!allowAggregation && !selectAggregateExprNodes.isEmpty()) {
        throw new ExprValidationException("Aggregation functions are not allowed in this context");
    }

    // Determine if we have a having clause with aggregation
    List<ExprAggregateNode> havingAggregateExprNodes = new LinkedList<ExprAggregateNode>();
    Set<Pair<Integer, String>> propertiesAggregatedHaving = new HashSet<Pair<Integer, String>>();
    if (optionalHavingNode != null) {
        ExprAggregateNodeUtil.getAggregatesBottomUp(optionalHavingNode, havingAggregateExprNodes);
        propertiesAggregatedHaving = ExprNodeUtility.getAggregatedProperties(havingAggregateExprNodes);
    }
    if (!allowAggregation && !havingAggregateExprNodes.isEmpty()) {
        throw new ExprValidationException("Aggregation functions are not allowed in this context");
    }

    // Determine if we have a order-by clause with aggregation
    List<ExprAggregateNode> orderByAggregateExprNodes = new LinkedList<ExprAggregateNode>();
    if (orderByNodes != null) {
        for (ExprNode orderByNode : orderByNodes) {
            ExprAggregateNodeUtil.getAggregatesBottomUp(orderByNode, orderByAggregateExprNodes);
        }
        if (!allowAggregation && !orderByAggregateExprNodes.isEmpty()) {
            throw new ExprValidationException("Aggregation functions are not allowed in this context");
        }
    }

    // Construct the appropriate aggregation service
    boolean hasGroupBy = !groupByNodes.isEmpty();
    AggregationService aggregationService = AggregationServiceFactory.getService(selectAggregateExprNodes,
            havingAggregateExprNodes, orderByAggregateExprNodes, hasGroupBy,
            stmtContext.getMethodResolutionService(), stmtContext, statementSpecCompiled.getAnnotations(),
            stmtContext.getVariableService(), stmtContext.getStatementStopService(),
            typeService.getEventTypes().length > 1, statementSpecCompiled.getFilterRootNode(),
            statementSpecCompiled.getHavingExprRootNode());

    boolean useCollatorSort = false;
    if (stmtContext.getConfigSnapshot() != null) {
        useCollatorSort = stmtContext.getConfigSnapshot().getEngineDefaults().getLanguage()
                .isSortUsingCollator();
    }

    // Construct the processor for sorting output events
    OrderByProcessor orderByProcessor = OrderByProcessorFactory.getProcessor(namedSelectionList, groupByNodes,
            orderByList, aggregationService, statementSpecCompiled.getRowLimitSpec(),
            stmtContext.getVariableService(), useCollatorSort);

    // Construct the processor for evaluating the select clause
    SelectExprEventTypeRegistry selectExprEventTypeRegistry = new SelectExprEventTypeRegistry(
            stmtContext.getDynamicReferenceEventTypes());
    SelectExprProcessor selectExprProcessor = SelectExprProcessorFactory.getProcessor(
            Collections.<Integer>emptyList(), selectClauseSpec.getSelectExprList(), isUsingWildcard,
            insertIntoDesc, statementSpecCompiled.getForClauseSpec(), typeService,
            stmtContext.getEventAdapterService(), stmtContext.getStatementResultService(),
            stmtContext.getValueAddEventService(), selectExprEventTypeRegistry,
            stmtContext.getMethodResolutionService(), stmtContext, stmtContext.getVariableService(),
            stmtContext.getTimeProvider(), stmtContext.getEngineURI(), stmtContext.getStatementId(),
            stmtContext.getStatementName(), stmtContext.getAnnotations());

    // Get a list of event properties being aggregated in the select clause, if any
    Set<Pair<Integer, String>> propertiesGroupBy = getGroupByProperties(groupByNodes);
    // Figure out all non-aggregated event properties in the select clause (props not under a sum/avg/max aggregation node)
    Set<Pair<Integer, String>> nonAggregatedProps = ExprNodeUtility.getNonAggregatedProps(selectNodes);
    if (optionalHavingNode != null) {
        ExprNodeUtility.addNonAggregatedProps(optionalHavingNode, nonAggregatedProps);
    }

    // Validate that group-by is filled with sensible nodes (identifiers, and not part of aggregates selected, no aggregates)
    validateGroupBy(groupByNodes);

    // Validate the having-clause (selected aggregate nodes and all in group-by are allowed)
    boolean hasAggregation = (!selectAggregateExprNodes.isEmpty()) || (!havingAggregateExprNodes.isEmpty())
            || (!orderByAggregateExprNodes.isEmpty()) || (!propertiesAggregatedHaving.isEmpty());
    if (optionalHavingNode != null && hasAggregation) {
        validateHaving(propertiesGroupBy, optionalHavingNode);
    }

    // We only generate Remove-Stream events if they are explicitly selected, or the insert-into requires them
    boolean isSelectRStream = (statementSpecCompiled
            .getSelectStreamSelectorEnum() == SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH
            || statementSpecCompiled
                    .getSelectStreamSelectorEnum() == SelectClauseStreamSelectorEnum.RSTREAM_ONLY);
    if ((statementSpecCompiled.getInsertIntoDesc() != null)
            && (!statementSpecCompiled.getInsertIntoDesc().isIStream())) {
        isSelectRStream = true;
    }

    // Determine if any output rate limiting must be performed early while processing results
    boolean isOutputLimiting = outputLimitSpec != null;
    if ((outputLimitSpec != null) && outputLimitSpec.getDisplayLimit() == OutputLimitLimitType.SNAPSHOT) {
        isOutputLimiting = false; // Snapshot output does not count in terms of limiting output for grouping/aggregation purposes
    }

    ExprEvaluator optionHavingEval = optionalHavingNode == null ? null : optionalHavingNode.getExprEvaluator();

    // (1)
    // There is no group-by clause and no aggregate functions with event properties in the select clause and having clause (simplest case)
    if ((groupByNodes.isEmpty()) && (selectAggregateExprNodes.isEmpty())
            && (havingAggregateExprNodes.isEmpty())) {
        // (1a)
        // There is no need to perform select expression processing, the single view itself (no join) generates
        // events in the desired format, therefore there is no output processor. There are no order-by expressions.
        if (orderByNodes.isEmpty() && optionalHavingNode == null && !isOutputLimiting
                && statementSpecCompiled.getRowLimitSpec() == null) {
            log.debug(".getProcessor Using no result processor");
            return new ResultSetProcessorHandThrough(selectExprProcessor, isSelectRStream);
        }

        // (1b)
        // We need to process the select expression in a simple fashion, with each event (old and new)
        // directly generating one row, and no need to update aggregate state since there is no aggregate function.
        // There might be some order-by expressions.
        log.debug(".getProcessor Using ResultSetProcessorSimple");
        return new ResultSetProcessorSimple(selectExprProcessor, orderByProcessor, optionHavingEval,
                isSelectRStream, stmtContext);
    }

    // (2)
    // A wildcard select-clause has been specified and the group-by is ignored since no aggregation functions are used, and no having clause
    boolean isLast = statementSpecCompiled.getOutputLimitSpec() != null
            && statementSpecCompiled.getOutputLimitSpec().getDisplayLimit() == OutputLimitLimitType.LAST;
    if ((namedSelectionList.isEmpty()) && (propertiesAggregatedHaving.isEmpty())
            && (havingAggregateExprNodes.isEmpty()) && (!isLast)) {
        log.debug(".getProcessor Using ResultSetProcessorSimple");
        return new ResultSetProcessorSimple(selectExprProcessor, orderByProcessor, optionHavingEval,
                isSelectRStream, stmtContext);
    }

    if ((groupByNodes.isEmpty()) && hasAggregation) {
        // (3)
        // There is no group-by clause and there are aggregate functions with event properties in the select clause (aggregation case)
        // or having class, and all event properties are aggregated (all properties are under aggregation functions).
        if ((nonAggregatedProps.isEmpty()) && (!isUsingWildcard) && (!isUsingStreamSelect)) {
            log.debug(".getProcessor Using ResultSetProcessorRowForAll");
            return new ResultSetProcessorRowForAll(selectExprProcessor, aggregationService, orderByProcessor,
                    optionHavingEval, isSelectRStream, isUnidirectional, stmtContext);
        }

        // (4)
        // There is no group-by clause but there are aggregate functions with event properties in the select clause (aggregation case)
        // or having clause and not all event properties are aggregated (some properties are not under aggregation functions).
        log.debug(".getProcessor Using ResultSetProcessorAggregateAll");
        return new ResultSetProcessorAggregateAll(selectExprProcessor, orderByProcessor, aggregationService,
                optionHavingEval, isSelectRStream, isUnidirectional, stmtContext);
    }

    // Handle group-by cases
    if (groupByNodes.isEmpty()) {
        throw new IllegalStateException("Unexpected empty group-by expression list");
    }

    // Figure out if all non-aggregated event properties in the select clause are listed in the group by
    Set<Pair<Integer, String>> nonAggregatedPropsSelect = ExprNodeUtility.getNonAggregatedProps(selectNodes);
    boolean allInGroupBy = true;
    if (isUsingStreamSelect) {
        allInGroupBy = false;
    }
    for (Pair<Integer, String> nonAggregatedProp : nonAggregatedPropsSelect) {
        if (!propertiesGroupBy.contains(nonAggregatedProp)) {
            allInGroupBy = false;
        }
    }

    // Wildcard select-clause means we do not have all selected properties in the group
    if (isUsingWildcard) {
        allInGroupBy = false;
    }

    // Figure out if all non-aggregated event properties in the order-by clause are listed in the select expression
    Set<Pair<Integer, String>> nonAggregatedPropsOrderBy = ExprNodeUtility.getNonAggregatedProps(orderByNodes);

    boolean allInSelect = true;
    for (Pair<Integer, String> nonAggregatedProp : nonAggregatedPropsOrderBy) {
        if (!nonAggregatedPropsSelect.contains(nonAggregatedProp)) {
            allInSelect = false;
        }
    }

    // Wildcard select-clause means that all order-by props in the select expression
    if (isUsingWildcard) {
        allInSelect = true;
    }

    // (4)
    // There is a group-by clause, and all event properties in the select clause that are not under an aggregation
    // function are listed in the group-by clause, and if there is an order-by clause, all non-aggregated properties
    // referred to in the order-by clause also appear in the select (output one row per group, not one row per event)
    ExprEvaluator[] groupByEval = ExprNodeUtility.getEvaluators(groupByNodes);
    if (allInGroupBy && allInSelect) {
        log.debug(".getProcessor Using ResultSetProcessorRowPerGroup");
        return new ResultSetProcessorRowPerGroup(selectExprProcessor, orderByProcessor, aggregationService,
                groupByEval, optionHavingEval, isSelectRStream, isUnidirectional, stmtContext, outputLimitSpec);
    }

    // (6)
    // There is a group-by clause, and one or more event properties in the select clause that are not under an aggregation
    // function are not listed in the group-by clause (output one row per event, not one row per group)
    log.debug(".getProcessor Using ResultSetProcessorAggregateGrouped");
    return new ResultSetProcessorAggregateGrouped(selectExprProcessor, orderByProcessor, aggregationService,
            groupByEval, optionHavingEval, isSelectRStream, isUnidirectional, stmtContext, outputLimitSpec);
}

From source file:com.navercorp.pinpoint.common.buffer.AutomaticBufferTest.java

@Test
public void testPutVInt() throws Exception {
    Buffer buffer = new AutomaticBuffer(0);
    buffer.putVInt(Integer.MAX_VALUE);
    buffer.putVInt(Integer.MIN_VALUE);
    buffer.putVInt(0);//from   www  . j  a v  a2  s. co m
    buffer.putVInt(1);
    buffer.putVInt(12345);

    buffer.setOffset(0);
    Assert.assertEquals(buffer.readVInt(), Integer.MAX_VALUE);
    Assert.assertEquals(buffer.readVInt(), Integer.MIN_VALUE);
    Assert.assertEquals(buffer.readVInt(), 0);
    Assert.assertEquals(buffer.readVInt(), 1);
    Assert.assertEquals(buffer.readVInt(), 12345);
}

From source file:IntVector.java

/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously./*from  w ww  .ja va 2 s .  c  o m*/
 *
 * @param s Int to remove from array
 *
 * @return True if the int was removed, false if it was not found
 */
public final boolean removeElement(int s) {

    for (int i = 0; i < m_firstFree; i++) {
        if (m_map[i] == s) {
            if ((i + 1) < m_firstFree)
                System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i);
            else
                m_map[i] = java.lang.Integer.MIN_VALUE;

            m_firstFree--;

            return true;
        }
    }

    return false;
}

From source file:com.cloudera.oryx.app.serving.als.model.ALSServingModel.java

void setItemVector(String item, float[] vector) {
    Preconditions.checkArgument(vector.length == features);
    int newPartition = lsh.getIndexFor(vector);
    // Exclusive update to mapping -- careful since other locks are acquired inside here
    try (AutoLock al = yPartitionMapLock.autoWriteLock()) {
        int existingPartition = yPartitionMap.getOrDefault(item, Integer.MIN_VALUE);
        if (existingPartition >= 0 && existingPartition != newPartition) {
            // Move from one to the other partition, so first remove old entry
            Y[existingPartition].removeVector(item);
            // Note that it's conceivable that a recommendation call sees *no* copy of this
            // item here in this brief window
        }/*from  w w w  .j ava  2  s  .  c o m*/
        // Then regardless put in new partition
        Y[newPartition].setVector(item, vector);
        yPartitionMap.put(item, newPartition);
    }
    try (AutoLock al = expectedItemIDsLock.autoWriteLock()) {
        expectedItemIDs.remove(item);
    }
    // Not clear if it's too inefficient to clear and recompute YtY solver every time any bit
    // of Y changes, but it's the most correct
    cachedYTYSolver.set(null);
}

From source file:com.edmunds.etm.runtime.api.ApplicationSeries.java

private void updateActiveVersion(SortedMap<ApplicationVersion, Application> versions) {

    // Find the version with the largest pool size
    Application majorityVersion = null;/*from  w w  w .  j a v  a  2s .c  om*/
    Application activeVersion = null;
    int maxPoolSize = Integer.MIN_VALUE;
    for (Application app : versions.values()) {
        int poolSize = app.getPoolSize();

        // The use of '>' gives us the oldest version in the case of a tie because
        // the values from the map are sorted in ascending version number order.
        if (poolSize > maxPoolSize) {
            maxPoolSize = poolSize;
            majorityVersion = app;
        }

        if (app.isActive()) {
            activeVersion = app;
        }
    }

    if (majorityVersion == null) {
        // Majority version is null only if no versions exist
        return;
    }

    // Has the active version changed?
    if (majorityVersion.equals(activeVersion)) {
        return;
    }

    versions.put(majorityVersion.getVersion(), new Application(majorityVersion, true));

    if (activeVersion != null) {
        versions.put(activeVersion.getVersion(), new Application(activeVersion, false));
    }
}