本文整理汇总了Java中org.apache.commons.lang.mutable.MutableInt.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java MutableInt.setValue方法的具体用法?Java MutableInt.setValue怎么用?Java MutableInt.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.mutable.MutableInt
的用法示例。
在下文中一共展示了MutableInt.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
/**
* Adds the specified <code>entry</code> into this priority queue. It is
* an error to call this method if the queue is full or if an entry already
* exists in the queue with the same key as <code>entry</code>'s key.
*
* @throws ArrayIndexOutOfBoundsException
* if this priority queue is full
* @throws IllegalArgumentException
* if this priority queue already contains an entry with the
* same key as <code>entry</code>'s key.
* @return true (indicating that the priority queue was modified)
*
* @see #isFull
* @see #pop
*/
@Override
public boolean add(Entry<V> entry) {
if (isFull()) {
throw new ArrayIndexOutOfBoundsException();
}
if (map.containsKey(entry.getKey())) {
throw new IllegalArgumentException("Duplicate key");
}
MutableInt m = (spare != null) ? spare : new MutableInt();
spare = null;
pq[++N] = entry;
m.setValue(N);
map.put(entry.getKey(), m);
swim(N);
return true;
}
示例2: run
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
@Override
public void run() {
//let the players update smoother
int remainingUpdates = getNextUpdates();
for (Map.Entry<Player, MutableInt> entry : queue.entrySet()) {
Player player = entry.getKey();
MutableInt remainingTicks = entry.getValue();
if (remainingTicks.intValue() == 0) {
if (remainingUpdates != 0) {
//Smoother refreshing; limit the updates
plugin.getScoreboardManager().onUpdate(player);
remainingTicks.setValue(20 * Settings.getInterval());
remainingUpdates--;
}
} else {
remainingTicks.decrement();
}
}
nextGlobalUpdate--;
if (nextGlobalUpdate == 0) {
nextGlobalUpdate = 20 * Settings.getInterval();
//update globals
plugin.getReplaceManager().updateGlobals();
}
}
示例3: loadData
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
private void loadData(final int maxCount)
{
final MutableInt doneCount = new MutableInt(0);
// Batches of 1000 objects
RetryingTransactionCallback<Integer> makeNodesCallback = new RetryingTransactionCallback<Integer>()
{
public Integer execute() throws Throwable
{
for (int i = 0; i < 1000; i++)
{
// We don't need to write anything
String contentUrl = FileContentStore.createNewFileStoreUrl();
ContentData contentData = new ContentData(contentUrl, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10, "UTF-8");
nodeHelper.makeNode(contentData);
int count = doneCount.intValue();
count++;
doneCount.setValue(count);
// Do some reporting
if (count % 1000 == 0)
{
System.out.println(String.format(" " + (new Date()) + "Total created: %6d", count));
}
// Double check for shutdown
if (vmShutdownListener.isVmShuttingDown())
{
break;
}
}
return maxCount;
}
};
int repetitions = (int) Math.floor((double)maxCount / 1000.0);
for (int i = 0; i < repetitions; i++)
{
transactionService.getRetryingTransactionHelper().doInTransaction(makeNodesCallback);
}
}
示例4: submitTask
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
/**
* Submit a log split task to executor service
* @param curTask task to submit
* @param curTaskZKVersion current version of task
*/
void submitTask(final String curTask, final RecoveryMode mode, final int curTaskZKVersion,
final int reportPeriod) {
final MutableInt zkVersion = new MutableInt(curTaskZKVersion);
CancelableProgressable reporter = new CancelableProgressable() {
private long last_report_at = 0;
@Override
public boolean progress() {
long t = EnvironmentEdgeManager.currentTime();
if ((t - last_report_at) > reportPeriod) {
last_report_at = t;
int latestZKVersion =
attemptToOwnTask(false, watcher, server.getServerName(), curTask,
mode, zkVersion.intValue());
if (latestZKVersion < 0) {
LOG.warn("Failed to heartbeat the task" + curTask);
return false;
}
zkVersion.setValue(latestZKVersion);
}
return true;
}
};
ZkSplitLogWorkerCoordination.ZkSplitTaskDetails splitTaskDetails =
new ZkSplitLogWorkerCoordination.ZkSplitTaskDetails();
splitTaskDetails.setTaskNode(curTask);
splitTaskDetails.setCurTaskZKVersion(zkVersion);
WALSplitterHandler hsh =
new WALSplitterHandler(server, this, splitTaskDetails, reporter,
this.tasksInProgress, splitTaskExecutor, mode);
server.getExecutorService().submit(hsh);
}
示例5: parseType
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
private Synonym.Type parseType(String value, MutableInt fromIndex) {
Synonym.Type type = Synonym.Type.RELATED;
while(fromIndex.intValue() < value.length()
&& Character.isWhitespace(value.charAt(fromIndex.intValue()))) {
fromIndex.increment();
}
int start = fromIndex.intValue();
while(fromIndex.intValue() < value.length()
&& Character.isLetter(value.charAt(fromIndex.intValue()))) {
fromIndex.increment();
}
if(start < fromIndex.intValue()) {
String scope = value.substring(start, fromIndex.intValue());
try {
type = Synonym.Type.valueOf(scope.toUpperCase());
} catch(IllegalArgumentException e) {
type = Synonym.Type.RELATED;
fromIndex.setValue(start);
}
}
return type;
}
示例6: submitTask
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
/**
* Submit a log split task to executor service
* @param curTask
* @param curTaskZKVersion
*/
void submitTask(final String curTask, final int curTaskZKVersion, final int reportPeriod) {
final MutableInt zkVersion = new MutableInt(curTaskZKVersion);
CancelableProgressable reporter = new CancelableProgressable() {
private long last_report_at = 0;
@Override
public boolean progress() {
long t = EnvironmentEdgeManager.currentTimeMillis();
if ((t - last_report_at) > reportPeriod) {
last_report_at = t;
int latestZKVersion =
attemptToOwnTask(false, watcher, serverName, curTask, zkVersion.intValue());
if (latestZKVersion < 0) {
LOG.warn("Failed to heartbeat the task" + curTask);
return false;
}
zkVersion.setValue(latestZKVersion);
}
return true;
}
};
HLogSplitterHandler hsh =
new HLogSplitterHandler(this.server, curTask, zkVersion, reporter, this.tasksInProgress,
this.splitTaskExecutor);
this.executorService.submit(hsh);
}
示例7: Crawler
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
@Test
public void executeCrawler_withSetupOfAnEmbeddedElasticSearchNode_expectNodeHttpToReturnStatusCode200After20seconds() throws FatalFault, UrlVisitException, ParseException, IndexDocumentException, InterruptedException, IOException {
final int expectedStatusCode = 200;
Crawler crawler = new Crawler();
CrawlerConfiguration crawlerConfiguration = setupCrawler();
// The async task for query the REST API found at the ElasticNode
final MutableInt actualStatusCode = new MutableInt();
Runnable askIndexIfIsAlive = () -> {
HttpClient4Builder httpClient4Builder = new HttpClient4Builder();
final CloseableHttpClient closeableHttpClient = httpClient4Builder.buildClientBuilder();
HttpGet target = new HttpGet("http://localhost:49231/");
try {
Integer statusCode = closeableHttpClient.execute(target, response1 -> response1.getStatusLine().getStatusCode());
actualStatusCode.setValue(statusCode);
} catch (IOException e) {
e.printStackTrace();
}
};
newScheduledThreadPool(1).schedule(crawler::killCrawler, 20, TimeUnit.SECONDS);
newScheduledThreadPool(1).schedule(askIndexIfIsAlive, 10, TimeUnit.SECONDS);
crawler.executeCrawler(crawlerConfiguration, crawlerWireObject);
assertEquals(expectedStatusCode, actualStatusCode.intValue());
}
示例8: exchange
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
private void exchange(int i, int j) {
Entry<V> t = pq[i];
pq[i] = pq[j];
pq[j] = t;
MutableInt m;
m = map.get(pq[i].getKey());
m.setValue(i);
m = map.get(pq[j].getKey());
m.setValue(j);
}
示例9: findNextEpisode_Continuous
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
private static CCEpisode findNextEpisode_Continuous(CCSeries s, List<CCEpisode> el, MutableInt continoousCount) {
CCDate d = CCDate.getMinimumDate();
for (int i = 0; i < el.size(); i++) {
if (!el.get(i).isViewed() || d.isGreaterThan(el.get(i).getViewedHistoryLast())) {
continoousCount.setValue(i);
return el.get(i);
}
d = el.get(i).getViewedHistoryLast();
}
continoousCount.setValue(0);
return el.get(0);
}
示例10: testGetAttributes
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
/**
* Checks that {@link AttributeService#getAttributes(AttributeQueryCallback, Serializable...) AttributeService.getAttributes}
* works. This includes coverage of <a href=https://issues.alfresco.com/jira/browse/MNT-9112>MNT-9112</a>.
*/
public void testGetAttributes() throws Exception
{
attributeService.setAttribute(VALUE_AAA_STRING, KEY_AAA);
attributeService.setAttribute(VALUE_AAB_STRING, KEY_AAB);
attributeService.setAttribute(VALUE_AAC_STRING, KEY_AAC);
final List<Serializable> results = new ArrayList<Serializable>();
final MutableInt counter = new MutableInt();
final MutableInt max = new MutableInt(3);
AttributeQueryCallback callback = new AttributeQueryCallback()
{
@Override
public boolean handleAttribute(Long id, Serializable value, Serializable[] keys)
{
counter.increment();
results.add(value);
if (counter.intValue() == max.intValue())
{
return false;
}
else
{
return true;
}
}
};
counter.setValue(0);
max.setValue(3);
results.clear();
attributeService.getAttributes(callback, KEY_A);
assertEquals(3, results.size());
assertEquals(3, counter.getValue());
counter.setValue(0);
max.setValue(2);
results.clear();
attributeService.getAttributes(callback, KEY_A);
assertEquals(2, results.size());
assertEquals(2, counter.getValue());
}
示例11: doAddUsers
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
private void doAddUsers(final MutableInt totalUsers, final MutableInt addedUsers,
final Map<String, String> results, final List<Map<QName,String>> users,
final ResourceBundle rb, final boolean sendEmails)
{
for (Map<QName,String> user : users)
{
totalUsers.setValue( totalUsers.intValue()+1 );
// Grab the username, and do any MT magic on it
String username = user.get(ContentModel.PROP_USERNAME);
try
{
username = PersonServiceImpl.updateUsernameForTenancy(username, tenantService);
}
catch (TenantDomainMismatchException e)
{
throw new ResourceBundleWebScriptException(
Status.STATUS_OK, rb,
ERROR_GENERAL, e);
}
// Do they already exist?
if (personService.personExists(username))
{
results.put(username, rb.getString(MSG_EXISTING));
if (logger.isDebugEnabled())
{
logger.debug("Not creating user as already exists: " + username + " for " + user);
}
}
else
{
String password = user.get(ContentModel.PROP_PASSWORD);
user.remove(ContentModel.PROP_PASSWORD); // Not for the person service
try
{
// Add the person
personService.createPerson( (Map<QName,Serializable>)(Map)user );
// Add the underlying user
authenticationService.createAuthentication(username, password.toCharArray());
// If required, notify the user
if (sendEmails)
{
personService.notifyPerson(username, password);
}
if (logger.isDebugEnabled())
{
logger.debug("Creating user from upload: " + username + " for " + user);
}
// All done
String msg = MessageFormat.format(
rb.getString(MSG_CREATED),
new Object[] { user.get(ContentModel.PROP_EMAIL) });
results.put(username, msg);
addedUsers.setValue( addedUsers.intValue()+1 );
}
catch (Throwable t)
{
throw new ResourceBundleWebScriptException(
Status.STATUS_OK, rb, ERROR_GENERAL, t);
}
}
}
}
示例12: prepareCharge
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
@Override
public int prepareCharge(final AccountFeeLog log) {
final Long[] groupIds = EntityHelper.toIds(log.getAccountFee().getGroups());
if (ArrayUtils.isEmpty(groupIds)) {
// No groups to charge
return 0;
}
final MutableInt result = new MutableInt();
String[] placeHolders = new String[groupIds.length];
Arrays.fill(placeHolders, "?");
StringBuilder sql = new StringBuilder();
sql.append(" insert into members_pending_charge");
sql.append(" (account_fee_log_id, member_id)");
sql.append(" select ?, id");
sql.append(" from members m");
sql.append(" where m.subclass = ?");
sql.append(" and m.group_id in (").append(StringUtils.join(placeHolders, ",")).append(')');
List<Object> args = new ArrayList<>(groupIds.length + 2);
args.add(log.getId());
args.add("M");
CollectionUtils.addAll(args, groupIds);
runNative(sql.toString(), args.toArray());
// Retrieve the number of inserted entities
sql = new StringBuilder();
sql.append(" select count(*) from into members_pending_charge");
sql.append(" join members m");
sql.append(" where m.subclass = ?");
sql.append(" and account_fee_log_id = ?");
sql.append(" and m.group_id in (").append(StringUtils.join(placeHolders, ",")).append(')');
Query query = entityManager.createNativeQuery(sql.toString(), Long.class);
query.setParameter(1, "M");
query.setParameter(2, log.getId());
for (int i = 0; i < groupIds.length; i++) {
query.setParameter(i+3, groupIds[i]);
}
int totalMembers = (int) query.getSingleResult();
result.setValue(totalMembers);
return result.intValue();
}
示例13: handleTagValue
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
@Override
void handleTagValue(String tag, String value,
String qualifierBlock, String comment) {
MutableInt fromIndex = new MutableInt();
String definition = substr(value, '"', '"', fromIndex);
if(definition == null) {
throw new InvalidFormatException("Invalid OBO def tag (missing quotes): " + value);
}
definition = context.unescapeTagValue(definition);
VersionedEntity entity = context.getCurrentEntity();
if(entity instanceof Term) {
Term term = (Term)entity;
term.setDefinition(definition);
String xrefList = substr(value, '[', ']', fromIndex);
if(xrefList != null) {
List<String> xrefs = split(xrefList, ',');
for(String xref : xrefs) {
int colon = indexOf(xref, ':', 0);
if(colon == -1) {
throw new InvalidFormatException("Invalid OBO xref (no datasource): " + xref);
}
String datasourceAcronym = xref.substring(0,colon);
int quote = indexOf(xref, '"', colon+1);
String refId = quote == -1 ? xref.substring(colon+1) : xref.substring(colon+1, quote);
datasourceAcronym = context.unescapeTagValue(datasourceAcronym);
refId = context.unescapeTagValue(refId);
CrossReference defXref = null;
if(UrlParser.isValidProtocol(datasourceAcronym)) {
String url = datasourceAcronym + ":" + refId;
defXref = addCrossReference(url, true);
} else {
defXref = addCrossReference(datasourceAcronym, refId, true);
}
if(quote != -1) {
fromIndex.setValue(quote);
String description = substr(xref, '"', '"', fromIndex);
description = context.unescapeTagValue(description);
defXref.setDescription(description);
}
}
}
} else if(entity instanceof RelationshipType) {
RelationshipType relationshipType = (RelationshipType)entity;
relationshipType.setDefintion(definition);
}
}
示例14: handleTagValue
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
@Override
void handleTagValue(String tag, String value,
String qualifierBlock, String comment) {
MutableInt fromIndex = new MutableInt();
String synonym = substr(value, '"', '"', fromIndex);
if(synonym == null) {
throw new InvalidFormatException("Invalid OBO synonym tag (missing quotes): " + value);
}
synonym = context.unescapeTagValue(synonym);
Synonym.Type type = parseType(value, fromIndex);
String xrefList = substr(value, '[', ']', fromIndex);
if(xrefList != null && xrefList.length() > 0) {
List<String> xrefs = split(xrefList, ',');
for(String xref : xrefs) {
int colon = indexOf(xref, ':', 0);
if(colon == -1) {
throw new InvalidFormatException("Invalid OBO synonym xref (no datasource): " + xref);
}
String datasource = xref.substring(0,colon);
int quote = indexOf(xref, '"', colon+1);
String refId = quote == -1 ? xref.substring(colon+1) : xref.substring(colon+1, quote);
datasource = context.unescapeTagValue(datasource);
refId = context.unescapeTagValue(refId);
Synonym synonymObj = null;
if(UrlParser.isValidProtocol(datasource)) {
String url = datasource + ":" + refId;
synonymObj = context.addSynonym(synonym, type, url);
} else {
synonymObj = context.addSynonym(synonym, type, datasource, refId);
}
if(quote != -1) {
fromIndex.setValue(quote);
String description = substr(xref, '"', '"', fromIndex);
description = context.unescapeTagValue(description);
synonymObj.setDescription(description);
}
}
} else {
context.addSynonym(synonym, type);
}
}
示例15: bestLowTangente
import org.apache.commons.lang.mutable.MutableInt; //导入方法依赖的package包/类
private Map<Integer, Double> bestLowTangente(Double[] pData, Double[] periodSmoothedFloor, MutableInt fTrouIdx, MutableInt lTrouIdx, MutableDouble amountAboveSmoothingFloor) {
Map<Integer, Double> lowTroughsMap = simpleLowTroughs(pData, periodSmoothedFloor, amountAboveSmoothingFloor);
Double[] troughs = lowTroughsMap.values().toArray(new Double[0]);
Double previousLeftTrough = null;
int previousLeftTroughIdx = -1;
double previousSlope = 0;
Double rightTrough = null;
int rightTroughIdx = troughs.length-1;
for (; rightTroughIdx >=0 ; rightTroughIdx--) {
if (troughs[rightTroughIdx] != 0) {
rightTrough = troughs[rightTroughIdx];
break;
}
}
if (rightTrough == null) return lowTroughsMap;
for (int leftTroughIdx = rightTroughIdx-1; leftTroughIdx >=0 ; leftTroughIdx--) {
if (troughs[leftTroughIdx] != 0) {
if (previousLeftTrough == null) {
previousLeftTrough = troughs[leftTroughIdx];
previousLeftTroughIdx = leftTroughIdx;
previousSlope = dataSlope((double)previousLeftTroughIdx, (double)rightTroughIdx, troughs);
} else {
//Check troughs[leftTroughIdx];
Boolean currentIsBelowPrevRegLine = troughs[leftTroughIdx] <= (leftTroughIdx-rightTroughIdx)*previousSlope + rightTrough;
if (currentIsBelowPrevRegLine) {//=> current is Below previous RegLine : current includes previous or is in opposite trend (up). We keep current
previousLeftTrough = troughs[leftTroughIdx];
previousLeftTroughIdx = leftTroughIdx;
previousSlope = dataSlope((double)previousLeftTroughIdx, (double)rightTroughIdx, troughs);
} else {//=> current is Above previous RegLine : current is cutting through previous regline or is in opposite trend (down). We keep previous.
continue;
}
}
}
}
fTrouIdx.setValue(previousLeftTroughIdx);
lTrouIdx.setValue(rightTroughIdx);
return lowTroughsMap;
}