Java Code Examples for org.apache.commons.lang.mutable.MutableInt#increment()

The following examples show how to use org.apache.commons.lang.mutable.MutableInt#increment() . 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: FlagMaker.java    From datawave with Apache License 2.0 7 votes vote down vote up
/**
 * Determine the number of unprocessed flag files in the flag directory
 * 
 * @param fc
 * @return the flag found for this ingest pool
 */
private int countFlagFileBacklog(final FlagDataTypeConfig fc) {
    final MutableInt fileCounter = new MutableInt(0);
    final FileFilter fileFilter = new WildcardFileFilter("*_" + fc.getIngestPool() + "_" + fc.getDataName() + "_*.flag");
    final FileVisitor<java.nio.file.Path> visitor = new SimpleFileVisitor<java.nio.file.Path>() {
        
        @Override
        public FileVisitResult visitFile(java.nio.file.Path path, BasicFileAttributes attrs) throws IOException {
            if (fileFilter.accept(path.toFile())) {
                fileCounter.increment();
            }
            return super.visitFile(path, attrs);
        }
    };
    try {
        Files.walkFileTree(Paths.get(fmc.getFlagFileDirectory()), visitor);
    } catch (IOException e) {
        // unable to get a flag count....
        log.error("Unable to get flag file count", e);
        return -1;
    }
    return fileCounter.intValue();
}
 
Example 2
Source File: FieldIndexCountingIteratorPerVisibility.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Given a Key to consume, update any necessary counters etc.
 *
 * @param key
 */
private void consume(Key key) {
    
    if (log.isTraceEnabled()) {
        log.trace("consume, key: " + key);
    }
    
    // update the visibility set
    MutableInt counter = this.currentVisibilityCounts.get(key.getColumnVisibility());
    if (counter == null) {
        this.currentVisibilityCounts.put(key.getColumnVisibility(), new MutableInt(1));
    } else {
        counter.increment();
    }
    
    // update current count
    this.count += 1;
    
    // set most recent timestamp
    this.maxTimeStamp = (this.maxTimeStamp > key.getTimestamp()) ? maxTimeStamp : key.getTimestamp();
}
 
Example 3
Source File: CasStatCounter.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
	this.docIt++;
	Optional<SourceDocumentInformation> sourceDocumentAnnotation = JCasUtils.getSourceDocumentAnnotation(aJCas);
	if(sourceDocumentAnnotation.isPresent())
		this.cumulatedFileSize += sourceDocumentAnnotation.get().getDocumentSize();
	FSIterator<Annotation> it =  aJCas.getAnnotationIndex().iterator();
	Annotation a;
	MutableInt i;
	while(it.hasNext()) {
		a = it.next();
		i = counters.get(a.getType().getShortName());
		if(i == null) 
			counters.put(a.getType().getShortName(), new MutableInt(1));
		else
			i.increment();
	}
	if(periodicStatEnabled && this.docIt % this.docPeriod == 0)
		try {
			traceToFile();
		} catch (IOException e) {
			throw new AnalysisEngineProcessException(e);
		}
}
 
Example 4
Source File: RequestUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private static FilterQuery traverseFilterQueryAndPopulateMap(FilterQueryTree tree,
    Map<Integer, FilterQuery> filterQueryMap, MutableInt currentId) {
  int currentNodeId = currentId.intValue();
  currentId.increment();

  final List<Integer> f = new ArrayList<>();
  if (null != tree.getChildren()) {
    for (final FilterQueryTree c : tree.getChildren()) {
      final FilterQuery q = traverseFilterQueryAndPopulateMap(c, filterQueryMap, currentId);
      int childNodeId = q.getId();
      f.add(childNodeId);
      filterQueryMap.put(childNodeId, q);
    }
  }

  FilterQuery query = new FilterQuery();
  query.setColumn(tree.getColumn());
  query.setId(currentNodeId);
  query.setNestedFilterQueryIds(f);
  query.setOperator(tree.getOperator());
  query.setValue(tree.getValue());
  return query;
}
 
Example 5
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCancelRunnableUsingRunnableReference() throws Exception {
	final MutableInt val = new MutableInt();
	Runnable test = new Runnable() {
		@Override
		public void run() {
			val.increment();
			cronService.cancel(this);
		}
	};
	cronService.schedule(test, "0/2 * * * * ?");
	sleep(5);
	assertEquals(val.intValue(), 1);
}
 
Example 6
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCancelRunnableUsingJobDetails() throws Exception {
	final MutableInt val = new MutableInt();
	Runnable test = new Runnable() {
		@Override
		public void run() {
			val.increment();
			cronService.cancel(cronService.getRunnables().get(this));
		}
	};
	cronService.schedule(test, "0/2 * * * * ?");
	sleep(5);
	assertEquals(val.intValue(), 1);
}
 
Example 7
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
private static Runnable newIncrementingRunnable(final MutableInt ref) {
	return new Runnable() {
		@Override
		public void run() {
			if (ref != null) {
				ref.increment();
			}
		}
	};
}
 
Example 8
Source File: TransactionRetryInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processException(Exception e, MethodInvocation invocation, MutableInt attempt) {

	StringBuilder message = new StringBuilder("When invoking method ")
		.append(invocation.getMethod().getDeclaringClass().getName()).append("#")
		.append(invocation.getMethod().getName()).append(" caught \"").append(e.getMessage())
		.append("\". Attempt #").append(attempt);

	attempt.increment();
	if (attempt.intValue() <= TransactionRetryInterceptor.MAX_ATTEMPTS) {
	    message.append(". Retrying.");
	} else {
	    message.append(". Giving up.");
	}
	TransactionRetryInterceptor.log.warn(message);
    }
 
Example 9
Source File: AnnotateVcfWithBamDepth.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
    final MutableInt depth = new MutableInt(0);
    for (final GATKRead read : readsContext) {
        if (!read.failsVendorQualityCheck() && !read.isDuplicate() && !read.isUnmapped() && read.getEnd() > read.getStart() && new SimpleInterval(read).contains(vc) ) {
            depth.increment();
        }
    }
    vcfWriter.add(new VariantContextBuilder(vc).attribute(POOLED_BAM_DEPTH_ANNOTATION_NAME, depth.intValue()).make());
}
 
Example 10
Source File: TopNUniqueSort.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * Adds object
 * @param e object to be added
 * @return true if offer() succeeds
 */
@SuppressWarnings("unchecked")
public boolean offer(E e)
{
  MutableInt ival = hmap.get(e);
  if (ival != null) { // already exists, so no insertion
    ival.increment();
    return true;
  }
  if (q.size() < qbound) {
    if (ival == null) {
      hmap.put(e, new MutableInt(1));
    }
    return q.offer(e);
  }

  boolean ret = false;
  boolean insert;
  Comparable<? super E> head = (Comparable<? super E>)q.peek();

  if (ascending) { // means head is the lowest value due to inversion
    insert = head.compareTo(e) < 0; // e > head
  } else { // means head is the highest value due to inversion
    insert = head.compareTo(e) > 0; // head is < e
  }

  // object e makes it, someone else gets dropped
  if (insert && q.offer(e)) {
    hmap.put(e, new MutableInt(1));
    ret = true;

    // the dropped object will never make it to back in anymore
    E drop = q.poll();
    hmap.remove(drop);
  }
  return ret;
}
 
Example 11
Source File: AnnotateVcfWithBamDepth.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
    final MutableInt depth = new MutableInt(0);
    for (final GATKRead read : readsContext) {
        if (!read.failsVendorQualityCheck() && !read.isDuplicate() && !read.isUnmapped() && read.getEnd() > read.getStart() && new SimpleInterval(read).contains(vc) ) {
            depth.increment();
        }
    }
    vcfWriter.add(new VariantContextBuilder(vc).attribute(POOLED_BAM_DEPTH_ANNOTATION_NAME, depth.intValue()).make());
}
 
Example 12
Source File: DagAwareYarnTaskScheduler.java    From tez with Apache License 2.0 5 votes vote down vote up
private void incrVertexTaskCount(Priority priority, RequestPriorityStats stats, int vertexIndex) {
  Integer vertexIndexInt = vertexIndex;
  MutableInt taskCount = stats.vertexTaskCount.get(vertexIndexInt);
  if (taskCount != null) {
    taskCount.increment();
  } else {
    addVertexToRequestStats(priority, stats, vertexIndexInt);
  }
}