Java Code Examples for org.apache.commons.lang3.mutable.MutableInt#intValue()
The following examples show how to use
org.apache.commons.lang3.mutable.MutableInt#intValue() .
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: IPCUtil.java From hbase with Apache License 2.0 | 6 votes |
static void execute(EventLoop eventLoop, Runnable action) { if (eventLoop.inEventLoop()) { // this is used to prevent stack overflow, you can see the same trick in netty's LocalChannel // implementation. MutableInt depth = DEPTH.get(); if (depth.intValue() < MAX_DEPTH) { depth.increment(); try { action.run(); } finally { depth.decrement(); } } else { eventLoop.execute(action); } } else { eventLoop.execute(action); } }
Example 2
Source File: SerdeFieldsDescriptor.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
@Override public synchronized Object deserializeObject(byte[] object, MutableInt offset) { Map<String, Type> fieldToType = Maps.newHashMap(); int length = GPOUtils.deserializeInt(object, offset); int startIndex = offset.intValue(); while (startIndex + length > offset.intValue()) { Type type = Type.values()[GPOUtils.deserializeInt(object, offset)]; String value = GPOUtils.deserializeString(object, offset); fieldToType.put(value, type); } return new FieldsDescriptor(fieldToType); }
Example 3
Source File: BulkLoadHFilesTool.java From hbase with Apache License 2.0 | 6 votes |
private boolean checkHFilesCountPerRegionPerFamily( final Multimap<ByteBuffer, LoadQueueItem> regionGroups) { for (Map.Entry<ByteBuffer, Collection<LoadQueueItem>> e : regionGroups.asMap().entrySet()) { Map<byte[], MutableInt> filesMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); for (LoadQueueItem lqi : e.getValue()) { MutableInt count = filesMap.computeIfAbsent(lqi.getFamily(), k -> new MutableInt()); count.increment(); if (count.intValue() > maxFilesPerRegionPerFamily) { LOG.error("Trying to load more than " + maxFilesPerRegionPerFamily + " hfiles to family " + Bytes.toStringBinary(lqi.getFamily()) + " of region with start key " + Bytes.toStringBinary(e.getKey())); return false; } } } return true; }
Example 4
Source File: JavaScriptJobManagerMinimalTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if an error occurs */ @Test public void addJob_multipleExecution_removeAllJobs() throws Exception { final MutableInt count = new MutableInt(0); final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) { @Override public void run() { count.increment(); if (count.intValue() >= 5) { manager_.removeAllJobs(); } } }; manager_.addJob(job, page_); manager_.waitForJobs(1000); assertEquals(5, count.intValue()); }
Example 5
Source File: JavaScriptJobManagerMinimalTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if an error occurs */ @Test public void addJob_multipleExecution_removeJob() throws Exception { final MutableInt id = new MutableInt(); final MutableInt count = new MutableInt(0); final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) { @Override public void run() { count.increment(); if (count.intValue() >= 5) { manager_.removeJob(id.intValue()); } } }; id.setValue(manager_.addJob(job, page_)); manager_.waitForJobs(1000); assertEquals(5, count.intValue()); }
Example 6
Source File: StructuredData.java From OpenModsLib with MIT License | 6 votes |
protected int addContainer(final int containerId, final C container, int firstElementId) { final MutableInt nextElementId = new MutableInt(firstElementId); container.createElements(element -> { final int elementId = nextElementId.intValue(); nextElementId.increment(); elements.put(elementId, element); containerToElement.put(containerId, elementId); elementToContainer.put(elementId, containerId); observer.onElementAdded(containerId, container, elementId, element); return elementId; }); containers.put(containerId, container); observer.onContainerAdded(containerId, container); return nextElementId.intValue(); }
Example 7
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
/** * This method deserializes a double from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized double. */ public static double deserializeDouble(byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); long val = (((long)buffer[0 + offsetInt]) & 0xFFL) << 56 | ((((long)buffer[1 + offsetInt]) & 0xFFL) << 48) | ((((long)buffer[2 + offsetInt]) & 0xFFL) << 40) | ((((long)buffer[3 + offsetInt]) & 0xFFL) << 32) | ((((long)buffer[4 + offsetInt]) & 0xFFL) << 24) | ((((long)buffer[5 + offsetInt]) & 0xFFL) << 16) | ((((long)buffer[6 + offsetInt]) & 0xFFL) << 8) | (((long)buffer[7 + offsetInt]) & 0xFFL); offset.add(Type.DOUBLE.getByteSize()); return Double.longBitsToDouble(val); }
Example 8
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * This method serializes the given character to the given byte buffer to the given offset, * the method also increments the offset appropriately. * @param val The value to serialize. * @param buffer The byte buffer to serialize to. * @param offset The offset in the buffer to serialize to and also to increment appropriately. */ public static void serializeChar(char val, byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); buffer[0 + offsetInt] = (byte)((val >> 8) & 0xFF); buffer[1 + offsetInt] = (byte)(val & 0xFF); offset.add(Type.CHAR.getByteSize()); }
Example 9
Source File: SimpleOffsetSerializer.java From teku with Apache License 2.0 | 5 votes |
private static void deserializeFixedElementList( SSZReader reader, MutableInt bytesPointer, Class listElementType, int currentObjectEndByte, SSZMutableList newSSZList) throws InstantiationException, InvocationTargetException, IllegalAccessException { while (bytesPointer.intValue() < currentObjectEndByte) { if (isContainer(listElementType)) { newSSZList.add(deserializeFixedContainer(listElementType, reader, bytesPointer)); } else if (isPrimitive(listElementType)) { newSSZList.add(deserializePrimitive(listElementType, reader, bytesPointer)); } } }
Example 10
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * This method deserializes a character from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized character. */ public static char deserializeChar(byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); char val = (char)(((((int)buffer[0 + offsetInt]) & 0xFF) << 8) | (((int)buffer[1 + offsetInt]) & 0xFF)); offset.add(Type.CHAR.getByteSize()); return val; }
Example 11
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * This method deserializes a short from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized short. */ public static short deserializeShort(byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); short val = (short)(((((int)buffer[0 + offsetInt]) & 0xFF) << 8) | (((int)buffer[1 + offsetInt]) & 0xFF)); offset.add(Type.SHORT.getByteSize()); return val; }
Example 12
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * This method deserializes a float from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized float. */ public static float deserializeFloat(byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); int val = ((((int)buffer[0 + offsetInt]) & 0xFF) << 24) | ((((int)buffer[1 + offsetInt]) & 0xFF) << 16) | ((((int)buffer[2 + offsetInt]) & 0xFF) << 8) | (((int)buffer[3 + offsetInt]) & 0xFF); offset.add(Type.FLOAT.getByteSize()); return Float.intBitsToFloat(val); }
Example 13
Source File: Hdf5MappingReader.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a consumer that adds to the value set of the {@link AttributeMetaData} and adds the mode value if it is * encountered. */ private Consumer<String> getValueSetFiller(AttributeMetaData attributeMetaData, int mode) { Set<String> valueSet = attributeMetaData.getValueSet(); MutableInt counter = new MutableInt(); return value -> { if (counter.intValue() == mode - 1) { attributeMetaData.setMode(value); } counter.increment(); valueSet.add(value); }; }
Example 14
Source File: BehaviourFilterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override @Extend(traitAPI = BehaviourFilterTrait.class, extensionAPI = BehaviourFilterExtension.class) public void enableBehaviour(QName className) { ParameterCheck.mandatory("className", className); if (logger.isDebugEnabled()) { logger.debug("Behaviour: ENABLE (" + AlfrescoTransactionSupport.getTransactionId() + "): " + className); } TransactionalResourceHelper.decrementCount(KEY_FILTER_COUNT, false); if (!TransactionalResourceHelper.isResourcePresent(KEY_CLASS_FILTERS)) { // Nothing was disabled return; } Map<ClassFilter, MutableInt> classFilters = TransactionalResourceHelper.getMap(KEY_CLASS_FILTERS); MutableInt filterNumber = null; for (ClassFilter classFilter : classFilters.keySet()) { if (classFilter.getClassName().equals(className)) { filterNumber = classFilters.get(classFilter); break; } } if (filterNumber == null) { // Class was not disabled return; } else if (filterNumber.intValue() <= 0) { // Can't go below zero for this } else { filterNumber.decrement(); } if (logger.isDebugEnabled()) { logger.debug(" Now: "+ filterNumber); } }
Example 15
Source File: BehaviourFilterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override @Extend(traitAPI = BehaviourFilterTrait.class, extensionAPI = BehaviourFilterExtension.class) public void enableBehaviour(NodeRef nodeRef, QName className) { ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("className", className); if (logger.isDebugEnabled()) { logger.debug("Behaviour: ENABLE (" + AlfrescoTransactionSupport.getTransactionId() + "): " + nodeRef + "/" + className); } TransactionalResourceHelper.decrementCount(KEY_FILTER_COUNT, false); if (!TransactionalResourceHelper.isResourcePresent(KEY_INSTANCE_CLASS_FILTERS)) { // Nothing was disabled return; } nodeRef = tenantService.getName(nodeRef); Map<NodeRef, Map<QName, MutableInt>> instanceClassFilters = TransactionalResourceHelper.getMap(KEY_INSTANCE_CLASS_FILTERS); Map<QName, MutableInt> classFilters = instanceClassFilters.get(nodeRef); if (classFilters == null) { // Instance classes were not disabled return; } MutableInt filter = classFilters.get(className); if (filter == null) { // Class was not disabled return; } else if (filter.intValue() <= 0) { // Can't go below zero for this } else { filter.decrement(); } if (logger.isDebugEnabled()) { logger.debug(" Now: "+ filter); } }
Example 16
Source File: BehaviourFilterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override @Extend(traitAPI = BehaviourFilterTrait.class, extensionAPI = BehaviourFilterExtension.class) public boolean isEnabled(NodeRef nodeRef, QName className) { ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("className", className); // Check the class (includes global) and instance, first if (!isEnabled(className) || !isEnabled(nodeRef)) { return false; } if (!TransactionalResourceHelper.isResourcePresent(KEY_INSTANCE_CLASS_FILTERS)) { // Nothing was disabled return true; } nodeRef = tenantService.getName(nodeRef); Map<NodeRef, Map<QName, MutableInt>> instanceClassFilters = TransactionalResourceHelper.getMap(KEY_INSTANCE_CLASS_FILTERS); Map<QName, MutableInt> classFilters = instanceClassFilters.get(nodeRef); if (classFilters == null) { // Instance classes were not disabled return true; } for (QName classCheck : classFilters.keySet()) { // Ignore if it is not part of the hierarchy we are requesting if (!dictionaryService.isSubClass(className, classCheck)) { continue; } MutableInt filter = classFilters.get(classCheck); if (filter != null && filter.intValue() > 0) { // Class was disabled return false; } } return true; }
Example 17
Source File: AttributeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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, (int)counter.getValue()); counter.setValue(0); max.setValue(2); results.clear(); attributeService.getAttributes(callback, KEY_A); assertEquals(2, results.size()); assertEquals(2, (int)counter.getValue()); }
Example 18
Source File: HumanTime.java From para with Apache License 2.0 | 4 votes |
/** * Appends an approximate, human-formatted representation of the time delta to the given {@link Appendable} object. * * @param <T> the return type * @param a the Appendable object, may not be <code>null</code> * @return the given Appendable object, never <code>null</code> */ public <T extends Appendable> T getApproximately(T a) { try { MutableInt parts = new MutableInt(0); long d = delta; long mod = d % YEAR; if (!append(d, mod, YEAR, 'y', a, parts)) { d %= YEAR; mod = d % MONTH; if (!append(d, mod, MONTH, 'n', a, parts) && parts.intValue() < 2) { d %= MONTH; mod = d % DAY; if (!append(d, mod, DAY, 'd', a, parts) && parts.intValue() < 2) { d %= DAY; mod = d % HOUR; if (!append(d, mod, HOUR, 'h', a, parts) && parts.intValue() < 2) { d %= HOUR; mod = d % MINUTE; if (!append(d, mod, MINUTE, 'm', a, parts) && parts.intValue() < 2) { d %= MINUTE; mod = d % SECOND; if (!append(d, mod, SECOND, 's', a, parts) && parts.intValue() < 2) { d %= SECOND; if (d > 0) { a.append(Integer.toString((int) d)); a.append('m'); a.append('s'); } } } } } } } } catch (IOException ex) { // What were they thinking... LoggerFactory.getLogger(HumanTime.class).warn(null, ex); } return a; }
Example 19
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 3 votes |
/** * This method serializes the given boolean to the given byte buffer to the given offset, * the method also increments the offset appropriately. * @param val The value to serialize. * @param buffer The byte buffer to serialize to. * @param offset The offset in the buffer to serialize to and also to increment appropriately. */ public static void serializeBoolean(boolean val, byte[] buffer, MutableInt offset) { buffer[offset.intValue()] = (byte)(val ? 1 : 0); offset.add(Type.BOOLEAN.getByteSize()); }
Example 20
Source File: TransactionalResourceHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 2 votes |
/** * Get the current count value for a named key * * @param resourceKey the key to count against * @return the current value for the named key */ public static final int getCount(Object resourceKey) { MutableInt counter = (MutableInt) AlfrescoTransactionSupport.getResource(resourceKey); return counter == null ? 0 : counter.intValue(); }