_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q168200
GeometryCodes.getGeometryType
validation
public static GeometryType getGeometryType(int code) { // Look at the last 2 digits to find the geometry type code int geometryTypeCode = code % 1000; GeometryType geometryType = null; switch (geometryTypeCode) { case 0: geometryType = GeometryType.GEOMETRY; break; case 1: geometryType = GeometryType.POINT; break; case 2: geometryType = GeometryType.LINESTRING; break; case 3: geometryType = GeometryType.POLYGON; break; case 4: geometryType = GeometryType.MULTIPOINT; break; case 5: geometryType = GeometryType.MULTILINESTRING; break; case 6: geometryType = GeometryType.MULTIPOLYGON; break; case 7: geometryType = GeometryType.GEOMETRYCOLLECTION; break; case 8: geometryType = GeometryType.CIRCULARSTRING; break; case 9: geometryType = GeometryType.COMPOUNDCURVE; break; case 10: geometryType = GeometryType.CURVEPOLYGON; break; case 11: geometryType = GeometryType.MULTICURVE; break; case 12: geometryType = GeometryType.MULTISURFACE; break; case 13: geometryType = GeometryType.CURVE; break; case 14: geometryType = GeometryType.SURFACE; break; case 15: geometryType = GeometryType.POLYHEDRALSURFACE; break; case 16: geometryType = GeometryType.TIN; break; case 17: geometryType = GeometryType.TRIANGLE; break; default: throw new SFException( "Unsupported Geometry code for type retrieval: " + code); } return geometryType; }
java
{ "resource": "" }
q168201
AbstractResource.exists
validation
@Override public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IoRuntimeException ex) { // Fall back to stream existence: can we open the stream? try { try (InputStream is = getInputStream()) { return true; } } catch (Throwable isEx) { return false; } } }
java
{ "resource": "" }
q168202
GcdCalculator.gcd
validation
public static long gcd(List<Long> l) { if (l.isEmpty()) { throw new IllegalArgumentException("List must contain at least one element"); } BigInteger gcd = BigInteger.valueOf(l.get(0)); for (Long num : l.subList(1, l.size())) { gcd = gcd.gcd(BigInteger.valueOf(num)); } return gcd.longValue(); }
java
{ "resource": "" }
q168203
StringUtils2.abbreviate
validation
@Nonnull public static String abbreviate(String str, int max) { if (str == null) { return ""; } else if (str.length() <= max) { return str; } else { return str.substring(0, max - 3) + "..."; } }
java
{ "resource": "" }
q168204
Json.value
validation
public static org.jmxtrans.agent.util.json.JsonValue value(String string) { return string == null ? NULL : new JsonString(string); }
java
{ "resource": "" }
q168205
Json.object
validation
public static org.jmxtrans.agent.util.json.JsonObject object() { return new org.jmxtrans.agent.util.json.JsonObject(); }
java
{ "resource": "" }
q168206
Json.parse
validation
public static org.jmxtrans.agent.util.json.JsonValue parse(String string) { if (string == null) { throw new NullPointerException("string is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(string); return handler.getValue(); }
java
{ "resource": "" }
q168207
ConfigurationUtils.getString
validation
public static String getString(Map<String, String> settings, String name, String defaultValue) { if (settings.containsKey(name)) { return settings.get(name); } else { return defaultValue; } }
java
{ "resource": "" }
q168208
JsonObject.readFrom
validation
@Deprecated public static JsonObject readFrom(String string) { return org.jmxtrans.agent.util.json.JsonValue.readFrom(string).asObject(); }
java
{ "resource": "" }
q168209
JsonObject.get
validation
public org.jmxtrans.agent.util.json.JsonValue get(String name) { if (name == null) { throw new NullPointerException("name is null"); } int index = indexOf(name); return index != -1 ? values.get(index) : null; }
java
{ "resource": "" }
q168210
JsonObject.iterator
validation
public Iterator<Member> iterator() { final Iterator<String> namesIterator = names.iterator(); final Iterator<org.jmxtrans.agent.util.json.JsonValue> valuesIterator = values.iterator(); return new Iterator<JsonObject.Member>() { public boolean hasNext() { return namesIterator.hasNext(); } public Member next() { String name = namesIterator.next(); org.jmxtrans.agent.util.json.JsonValue value = valuesIterator.next(); return new Member(name, value); } public void remove() { throw new UnsupportedOperationException(); } }; }
java
{ "resource": "" }
q168211
PropertyPlaceholderResolver.resolvePlaceholder
validation
protected String resolvePlaceholder(String property, String defaultValue) throws IllegalStateException { // "graphite.host" -> "GRAPHITE_HOST" String environmentVariableStyleProperty = property.toUpperCase(); environmentVariableStyleProperty = environmentVariableStyleProperty.replaceAll("\\.", "_"); String result; if (externalProperties.containsKey(property)) { result = externalProperties.get(property); } else if (System.getProperties().containsKey(property)) { result = System.getProperty(property); } else if (System.getenv().containsKey(property)) { result = System.getenv(property); } else if (System.getenv().containsKey(environmentVariableStyleProperty)) { result = System.getenv(environmentVariableStyleProperty); } else if (defaultValue != null) { result = defaultValue; } else { throw new IllegalStateException("Property '" + property + "' not found in System properties nor in Environment variables"); } return result; }
java
{ "resource": "" }
q168212
JmxTransAgent.getVersionInfo
validation
@Nonnull public static String getVersionInfo() { Package pkg = JmxTransAgent.class.getPackage(); if (pkg == null) { return "jmxtrans-agent"; } else { return pkg.getImplementationTitle() + ": " + pkg.getImplementationVersion(); } }
java
{ "resource": "" }
q168213
JsonArray.readFrom
validation
@Deprecated public static JsonArray readFrom(String string) { return org.jmxtrans.agent.util.json.JsonValue.readFrom(string).asArray(); }
java
{ "resource": "" }
q168214
JsonArray.add
validation
public JsonArray add(org.jmxtrans.agent.util.json.JsonValue value) { if (value == null) { throw new NullPointerException("value is null"); } values.add(value); return this; }
java
{ "resource": "" }
q168215
JsonArray.set
validation
public JsonArray set(int index, org.jmxtrans.agent.util.json.JsonValue value) { if (value == null) { throw new NullPointerException("value is null"); } values.set(index, value); return this; }
java
{ "resource": "" }
q168216
JsonArray.get
validation
public org.jmxtrans.agent.util.json.JsonValue get(int index) { return values.get(index); }
java
{ "resource": "" }
q168217
JsonArray.values
validation
public List<org.jmxtrans.agent.util.json.JsonValue> values() { return Collections.unmodifiableList(values); }
java
{ "resource": "" }
q168218
JsonArray.iterator
validation
public Iterator<org.jmxtrans.agent.util.json.JsonValue> iterator() { final Iterator<org.jmxtrans.agent.util.json.JsonValue> iterator = values.iterator(); return new Iterator<org.jmxtrans.agent.util.json.JsonValue>() { public boolean hasNext() { return iterator.hasNext(); } public org.jmxtrans.agent.util.json.JsonValue next() { return iterator.next(); } public void remove() { throw new UnsupportedOperationException(); } }; }
java
{ "resource": "" }
q168219
EventMonitor.processEvent
validation
private void processEvent(final Object event) { System.out.println("Processing event: " + event.toString()); for (final EventHandler handler : getConsumersFor(event.getClass())) { EVENT_EXECUTOR.execute(new Runnable(){ @Override public void run() { try { handler.handle(event); } catch(Exception e) { e.printStackTrace(); if (shouldReRaiseOnError) { System.out.println("Event handler failed. Re-publishing event: " + event.toString()); eventQueue.publish(event); } } } }); } }
java
{ "resource": "" }
q168220
DomainEvents.publishEvent
validation
private void publishEvent(Object event) { assert(hasEventBusses()); for (EventBus eventBus : eventBusses.values()) { eventBus.publish(event); } }
java
{ "resource": "" }
q168221
DomainEvents.publishEvent
validation
private void publishEvent(String name, Object event) { assert(hasEventBusses()); EventBus eventBus = getEventBus(name); if (eventBus == null) { throw new RuntimeException("Unknown event bus name: " + name); } eventBus.publish(event); }
java
{ "resource": "" }
q168222
NoTag.removeChild
validation
public void removeChild(final String child) { final StringBuilder htmlMiddleSB = getHtmlMiddleSB(); final String sb = htmlMiddleSB.toString(); final String replaced = sb.replace(child, ""); final int lastIndex = htmlMiddleSB.length() - 1; htmlMiddleSB.delete(0, lastIndex); htmlMiddleSB.append(replaced); }
java
{ "resource": "" }
q168223
InnerHtmlAddListenerImpl.addInWffIdMap
validation
private void addInWffIdMap(final AbstractHtml tag) { final Deque<Set<AbstractHtml>> childrenStack = new ArrayDeque<>(); // passed 2 instead of 1 because the load factor is 0.75f final Set<AbstractHtml> initialSet = new HashSet<>(2); initialSet.add(tag); childrenStack.push(initialSet); Set<AbstractHtml> children; while ((children = childrenStack.poll()) != null) { for (final AbstractHtml child : children) { final DataWffId wffIdAttr = child.getDataWffId(); if (wffIdAttr != null) { tagByWffId.put(wffIdAttr.getValue(), child); } final Set<AbstractHtml> subChildren = child .getChildren(accessObject); if (subChildren != null && subChildren.size() > 0) { childrenStack.push(subChildren); } } } }
java
{ "resource": "" }
q168224
AbstractAttribute.addToAttributeValueMap
validation
protected boolean addToAttributeValueMap(final String key, final String value) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); try { final Map<String, String> attributeValueMap = getAttributeValueMap(); final String previousValue = attributeValueMap.put(key, value); if (!Objects.equals(previousValue, value)) { setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); return listenerInvoked; }
java
{ "resource": "" }
q168225
AbstractAttribute.invokeValueChangeListeners
validation
private void invokeValueChangeListeners( final Collection<AbstractHtml5SharedObject> sharedObjects) { for (final AbstractHtml5SharedObject sharedObject : sharedObjects) { final AttributeValueChangeListener valueChangeListener = sharedObject .getValueChangeListener(ACCESS_OBJECT); if (valueChangeListener != null) { // ownerTags should not be modified in the consuming // part, here // skipped it making unmodifiable to gain // performance final AttributeValueChangeListener.Event event = new AttributeValueChangeListener.Event( this, ownerTags); valueChangeListener.valueChanged(event); } } if (valueChangeListeners != null) { for (final AttributeValueChangeListener listener : valueChangeListeners) { final AttributeValueChangeListener.Event event = new AttributeValueChangeListener.Event( this, Collections.unmodifiableSet(ownerTags)); listener.valueChanged(event); } } }
java
{ "resource": "" }
q168226
AbstractAttribute.addAllToAttributeValueMap
validation
protected boolean addAllToAttributeValueMap(final Map<String, String> map) { if (map != null && map.size() > 0) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); try { getAttributeValueMap().putAll(map); setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); return listenerInvoked; } return false; }
java
{ "resource": "" }
q168227
AbstractAttribute.removeFromAttributeValueMapByKeys
validation
protected boolean removeFromAttributeValueMapByKeys(final String... keys) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); boolean result = false; try { final Map<String, String> valueMap = getAttributeValueMap(); if (nullableAttrValueMapValue) { for (final String key : keys) { result = valueMap.containsKey(key); if (result) { break; } } } for (final String key : keys) { final String previous = valueMap.remove(key); if (previous != null) { result = true; } } if (result) { setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); return result; }
java
{ "resource": "" }
q168228
AbstractAttribute.pushQueues
validation
private void pushQueues( final Collection<AbstractHtml5SharedObject> sharedObjects, final boolean listenerInvoked) { if (listenerInvoked) { for (final AbstractHtml5SharedObject sharedObject : sharedObjects) { final PushQueue pushQueue = sharedObject .getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } } } }
java
{ "resource": "" }
q168229
AbstractAttribute.removeFromAttributeValueMap
validation
protected boolean removeFromAttributeValueMap(final String key, final String value) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); boolean listenerInvoked = false; try { final boolean removed = getAttributeValueMap().remove(key, value); if (removed) { setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); return listenerInvoked; }
java
{ "resource": "" }
q168230
AbstractAttribute.addToAttributeValueSet
validation
protected boolean addToAttributeValueSet(final String value) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); try { final boolean added = getAttributeValueSet().add(value); if (added) { setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); return listenerInvoked; }
java
{ "resource": "" }
q168231
AbstractAttribute.addAllToAttributeValueSet
validation
protected void addAllToAttributeValueSet(final Collection<String> values) { if (values != null) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); try { final boolean added = getAttributeValueSet().addAll(values); if (added) { setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); } }
java
{ "resource": "" }
q168232
AbstractAttribute.removeAllFromAttributeValueSet
validation
protected void removeAllFromAttributeValueSet( final Collection<String> values) { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); try { final boolean removedAll = getAttributeValueSet().removeAll(values); if (removedAll) { setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); }
java
{ "resource": "" }
q168233
AbstractAttribute.removeAllFromAttributeValueSet
validation
protected void removeAllFromAttributeValueSet() { final Collection<AbstractHtml5SharedObject> sharedObjects = getSharedObjects(); boolean listenerInvoked = false; final Collection<WriteLock> writeLocks = lockAndGetWriteLocks(); try { getAttributeValueSet().clear(); setModified(true); invokeValueChangeListeners(sharedObjects); listenerInvoked = true; } finally { for (final Lock lock : writeLocks) { lock.unlock(); } } pushQueues(sharedObjects, listenerInvoked); }
java
{ "resource": "" }
q168234
AbstractAttribute.addValueChangeListener
validation
public void addValueChangeListener( final AttributeValueChangeListener valueChangeListener) { if (valueChangeListeners == null) { synchronized (this) { if (valueChangeListeners == null) { valueChangeListeners = new LinkedHashSet<>(); } } } valueChangeListeners.add(valueChangeListener); }
java
{ "resource": "" }
q168235
Pattern.containsValidRegEx
validation
public boolean containsValidRegEx() { try { java.util.regex.Pattern.compile(super.getAttributeValue()); return true; } catch (final PatternSyntaxException e) { // NOP } return false; }
java
{ "resource": "" }
q168236
RgbaCssValue.setR
validation
public void setR(final int r) { if (r < 0 || r > 255) { throw new InvalidValueException( "r paramater accept values only from 0 to 255."); } this.r = r; rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")"; if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } }
java
{ "resource": "" }
q168237
RgbaCssValue.setG
validation
public void setG(final int g) { if (g < 0 || g > 255) { throw new InvalidValueException( "g paramater accept values only from 0 to 255."); } this.g = g; rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")"; if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } }
java
{ "resource": "" }
q168238
RgbaCssValue.setB
validation
public void setB(final int b) { if (b < 0 || b > 255) { throw new InvalidValueException( "b paramater accept values only from 0 to 255."); } this.b = b; rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")"; if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } }
java
{ "resource": "" }
q168239
RgbaCssValue.setA
validation
public void setA(final float a) { if (a < 0 || a > 1) { throw new InvalidValueException( "a paramater accept values only from 0 to 255."); } this.a = a; rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")"; if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } }
java
{ "resource": "" }
q168240
TagRegistry.loadAllTagClasses
validation
public static void loadAllTagClasses() { final Map<String, Class<?>> unloadedClasses = new HashMap<>(); for (final Entry<String, Class<?>> entry : tagClassByTagNameTmp .entrySet()) { try { Class.forName(entry.getValue().getName()); } catch (final ClassNotFoundException e) { unloadedClasses.put(entry.getKey(), entry.getValue()); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("Could not load tag class " + entry.getValue().getName()); } } } tagClassByTagNameTmp.clear(); if (unloadedClasses.size() > 0) { tagClassByTagNameTmp.putAll(unloadedClasses); } else { tagClassByTagNameTmp = null; } }
java
{ "resource": "" }
q168241
StringUtil.getFirstSubstring
validation
public static String getFirstSubstring(final String inputString, final String startingWith, final String endingWith) { if (!inputString.contains(startingWith) || !inputString.contains(endingWith)) { return null; } final int startIndex = inputString.indexOf(startingWith); if (!((startIndex + 1) < inputString.length())) { return null; } final int endIndex = inputString.indexOf(endingWith, startIndex + 1) + 1; if (startIndex > endIndex || startIndex < 0 || endIndex < 0) { return null; } return inputString.substring(startIndex, endIndex); }
java
{ "resource": "" }
q168242
StringUtil.cloneArray
validation
public static String[] cloneArray(final String[] inputArray) { final String[] array = new String[inputArray.length]; System.arraycopy(inputArray, 0, array, 0, inputArray.length); return array; }
java
{ "resource": "" }
q168243
StringUtil.containsWhitespace
validation
public static boolean containsWhitespace(final String string) { for (int i = 0; i < string.length(); i++) { if (Character.isWhitespace(string.charAt(i))) { return true; } } return false; }
java
{ "resource": "" }
q168244
StringUtil.strip
validation
public static String strip(final String s) { int first; int last; for (first = 0; first < s.length(); first++) { if (!Character.isWhitespace(s.charAt(first))) { break; } } for (last = s.length(); last > first; last--) { if (!Character.isWhitespace(s.charAt(last - 1))) { break; } } return s.substring(first, last); }
java
{ "resource": "" }
q168245
AbstractHtml.removeAllChildren
validation
public void removeAllChildren() { boolean listenerInvoked = false; final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); try { lock.lock(); final AbstractHtml[] removedAbstractHtmls = children .toArray(new AbstractHtml[children.size()]); children.clear(); initNewSharedObjectInAllNestedTagsAndSetSuperParentNull( removedAbstractHtmls); final ChildTagRemoveListener listener = sharedObject .getChildTagRemoveListener(ACCESS_OBJECT); if (listener != null) { listener.allChildrenRemoved(new ChildTagRemoveListener.Event( this, removedAbstractHtmls)); listenerInvoked = true; } } finally { lock.unlock(); } if (listenerInvoked) { final PushQueue pushQueue = sharedObject .getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } } }
java
{ "resource": "" }
q168246
AbstractHtml.addInnerHtmls
validation
protected void addInnerHtmls(final boolean updateClient, final AbstractHtml... innerHtmls) { boolean listenerInvoked = false; final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); try { lock.lock(); final AbstractHtml[] removedAbstractHtmls = children .toArray(new AbstractHtml[children.size()]); children.clear(); initNewSharedObjectInAllNestedTagsAndSetSuperParentNull( removedAbstractHtmls); final InnerHtmlAddListener listener = sharedObject .getInnerHtmlAddListener(ACCESS_OBJECT); if (listener != null && updateClient) { final InnerHtmlAddListener.Event[] events = new InnerHtmlAddListener.Event[innerHtmls.length]; int index = 0; for (final AbstractHtml innerHtml : innerHtmls) { AbstractHtml previousParentTag = null; if (innerHtml.parent != null && innerHtml.parent.sharedObject == sharedObject) { previousParentTag = innerHtml.parent; } addChild(innerHtml, false); events[index] = new InnerHtmlAddListener.Event(this, innerHtml, previousParentTag); index++; } listener.innerHtmlsAdded(this, events); listenerInvoked = true; } else { for (final AbstractHtml innerHtml : innerHtmls) { addChild(innerHtml, false); } } } finally { lock.unlock(); } if (listenerInvoked) { final PushQueue pushQueue = sharedObject .getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } } }
java
{ "resource": "" }
q168247
AbstractHtml.removeChildren
validation
public boolean removeChildren(final Collection<AbstractHtml> children) { final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); boolean result = false; try { lock.lock(); result = this.children.removeAll(children); } finally { lock.unlock(); } final PushQueue pushQueue = sharedObject.getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } return result; }
java
{ "resource": "" }
q168248
AbstractHtml.removeChild
validation
public boolean removeChild(final AbstractHtml child) { boolean listenerInvoked = false; final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); boolean removed = false; try { lock.lock(); removed = children.remove(child); if (removed) { // making child.parent = null inside the below method. initNewSharedObjectInAllNestedTagsAndSetSuperParentNull(child); final ChildTagRemoveListener listener = sharedObject .getChildTagRemoveListener(ACCESS_OBJECT); if (listener != null) { listener.childRemoved( new ChildTagRemoveListener.Event(this, child)); listenerInvoked = true; } } } finally { lock.unlock(); } if (listenerInvoked) { final PushQueue pushQueue = sharedObject .getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } } return removed; }
java
{ "resource": "" }
q168249
AbstractHtml.appendChildren
validation
public void appendChildren(final Collection<AbstractHtml> children) { boolean listenerInvoked = false; final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); try { lock.lock(); final Collection<ChildMovedEvent> movedOrAppended = new ArrayDeque<>( children.size()); for (final AbstractHtml child : children) { final AbstractHtml previousParent = child.parent; addChild(child, false); final ChildMovedEvent event = new ChildMovedEvent( previousParent, this, child); movedOrAppended.add(event); } final ChildTagAppendListener listener = sharedObject .getChildTagAppendListener(ACCESS_OBJECT); if (listener != null) { listener.childrendAppendedOrMoved(movedOrAppended); listenerInvoked = true; } } finally { lock.unlock(); } if (listenerInvoked) { final PushQueue pushQueue = sharedObject .getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } } }
java
{ "resource": "" }
q168250
AbstractHtml.initAttributes
validation
private void initAttributes(final AbstractAttribute... attributes) { if (attributes == null || attributes.length == 0) { return; } // initial capacity must be greater than 1 instead of 1 // because the load factor is 0.75f // possible initial attributes on a tag may be maximum 8 // they may be id, name, class, value, style, onchange, placeholder attributesMap = new ConcurrentHashMap<>(8); for (final AbstractAttribute attribute : attributes) { attributesMap.put(attribute.getAttributeName(), attribute); } this.attributes = new AbstractAttribute[attributesMap.size()]; attributesMap.values().toArray(this.attributes); }
java
{ "resource": "" }
q168251
AbstractHtml.getAttributeByName
validation
public AbstractAttribute getAttributeByName(final String attributeName) { final Lock lock = sharedObject.getLock(ACCESS_OBJECT).readLock(); AbstractAttribute result = null; try { lock.lock(); if (attributesMap != null) { result = attributesMap.get(attributeName); } } finally { lock.unlock(); } return result; }
java
{ "resource": "" }
q168252
AbstractHtml.markOwnerTag
validation
private void markOwnerTag(final AbstractAttribute[] attributes) { if (attributes == null) { return; } for (final AbstractAttribute abstractAttribute : attributes) { abstractAttribute.setOwnerTag(this); } }
java
{ "resource": "" }
q168253
AbstractHtml.initInConstructor
validation
private void initInConstructor() { htmlStartSB = new StringBuilder(tagName == null ? 0 : tagName.length() + 2 + ((attributes == null ? 0 : attributes.length) * 16)); htmlEndSB = new StringBuilder( tagName == null ? 16 : tagName.length() + 3); }
java
{ "resource": "" }
q168254
AbstractHtml.getChildrenAsArray
validation
public AbstractHtml[] getChildrenAsArray() { final Lock lock = sharedObject.getLock(ACCESS_OBJECT).readLock(); try { lock.lock(); return children.toArray(new AbstractHtml[children.size()]); } finally { lock.unlock(); } }
java
{ "resource": "" }
q168255
AbstractHtml.getFirstChild
validation
public AbstractHtml getFirstChild() { // this block must be synchronized otherwise may get null or // ConcurrentModificationException // the test cases are written to check its thread safety and can be // reproduce by uncommenting this synchronized block, checkout // AbstractHtmlTest class for it. // synchronized (children) { // // } // it's been replaced with locking final Lock lock = sharedObject.getLock(ACCESS_OBJECT).readLock(); try { lock.lock(); // this must be most efficient because the javadoc of findFirst says // "This is a short-circuiting terminal operation." // return (T) children.stream().findFirst().orElse(null); // but as per CodePerformanceTest.testPerformanceOfFindFirst // the below is faster final Iterator<AbstractHtml> iterator = children.iterator(); if (iterator.hasNext()) { return iterator.next(); } return null; } finally { lock.unlock(); } }
java
{ "resource": "" }
q168256
AbstractHtml.getChildrenSize
validation
public int getChildrenSize() { final Lock lock = sharedObject.getLock(ACCESS_OBJECT).readLock(); try { lock.lock(); return children.size(); } finally { lock.unlock(); } }
java
{ "resource": "" }
q168257
AbstractHtml.containsChild
validation
public boolean containsChild(final AbstractHtml childTag) { final Lock lock = sharedObject.getLock(ACCESS_OBJECT).readLock(); try { lock.lock(); return children.contains(childTag); } finally { lock.unlock(); } }
java
{ "resource": "" }
q168258
AbstractHtml.getOpeningTag
validation
public final String getOpeningTag() { if (isRebuild() || isModified()) { final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); try { lock.lock(); buildOpeningTag(true); } finally { lock.unlock(); } } return openingTag; }
java
{ "resource": "" }
q168259
AbstractHtml.insertBefore
validation
public boolean insertBefore(final AbstractHtml... abstractHtmls) { if (parent == null) { throw new NoParentException("There must be a parent for this tag."); } final Lock lock = sharedObject.getLock(ACCESS_OBJECT).writeLock(); boolean result = false; try { lock.lock(); final AbstractHtml[] removedParentChildren = parent.children .toArray(new AbstractHtml[parent.children.size()]); result = insertBefore(removedParentChildren, abstractHtmls); } finally { lock.unlock(); } final PushQueue pushQueue = sharedObject.getPushQueue(ACCESS_OBJECT); if (pushQueue != null) { pushQueue.push(); } return result; }
java
{ "resource": "" }
q168260
AbstractValueSetAttribute.setAttributeValue
validation
@Override protected void setAttributeValue(final boolean updateClient, final String value) { if (value != null) { final Collection<String> allValues = extractValues(value); super.replaceAllInAttributeValueSet(updateClient, allValues); } }
java
{ "resource": "" }
q168261
AbstractValueSetAttribute.replaceAllInAttributeValueSet
validation
protected void replaceAllInAttributeValueSet(final boolean updateClient, final String... attrValues) { if (attrValues != null) { final Collection<String> allValues = new ArrayDeque<>(); for (final String attrValue : attrValues) { if (attrValue != null) { allValues.addAll(extractValues(attrValue)); } } super.replaceAllInAttributeValueSet(updateClient, allValues); } }
java
{ "resource": "" }
q168262
BrowserPage.addWebSocketPushListener
validation
public final void addWebSocketPushListener(final String sessionId, final WebSocketPushListener wsListener) { sessionIdWsListeners.put(sessionId, wsListener); wsListeners.push(wsListener); this.wsListener = wsListener; if (pushQueueOnNewWebSocketListener) { pushWffBMBytesQueue(); } }
java
{ "resource": "" }
q168263
BrowserPage.removeWebSocketPushListener
validation
public final void removeWebSocketPushListener(final String sessionId) { final WebSocketPushListener removed = sessionIdWsListeners .remove(sessionId); wsListeners.remove(removed); wsListener = wsListeners.peek(); }
java
{ "resource": "" }
q168264
BrowserPage.removeFromContext
validation
public final void removeFromContext(final boolean enable, final On... ons) { for (final On on : ons) { if (On.TAB_CLOSE.equals(on)) { removeFromBrowserContextOnTabClose = enable; } else if (On.INIT_REMOVE_PREVIOUS.equals(on)) { removePrevFromBrowserContextOnTabInit = enable; } } }
java
{ "resource": "" }
q168265
BrowserPage.getTagRepository
validation
public final TagRepository getTagRepository() { if (tagRepository == null && rootTag != null) { synchronized (this) { if (tagRepository == null) { tagRepository = new TagRepository(ACCESS_OBJECT, this, tagByWffId, rootTag); } } } return tagRepository; }
java
{ "resource": "" }
q168266
BrowserPage.setNonceForWffScript
validation
protected final void setNonceForWffScript(final String value) { if (autoremoveWffScript) { throw new InvalidUsageException( "Cannot remove while autoremoveWffScript is set as true. Please do setAutoremoveWffScript(false)"); } if (value != null) { if (nonceForWffScriptTag == null) { nonceForWffScriptTag = new Nonce(value); if (wffScriptTagId != null) { final AbstractHtml[] ownerTags = wffScriptTagId .getOwnerTags(); if (ownerTags.length > 0) { final AbstractHtml wffScript = ownerTags[0]; wffScript.addAttributes(nonceForWffScriptTag); } } } else { nonceForWffScriptTag.setValue(value); } } else { if (wffScriptTagId != null && nonceForWffScriptTag != null) { final AbstractHtml[] ownerTags = wffScriptTagId.getOwnerTags(); if (ownerTags.length > 0) { final AbstractHtml wffScript = ownerTags[0]; wffScript.removeAttributes(nonceForWffScriptTag); } } nonceForWffScriptTag = null; } }
java
{ "resource": "" }
q168267
Border.setBorderStyle
validation
public Border setBorderStyle(final BorderStyle borderStyle) { if (borderStyle == BorderStyle.INITIAL || borderStyle == BorderStyle.INHERIT) { throw new InvalidValueException("the given borderStyle cannot be " + borderStyle.getCssValue()); } final StringBuilder cssValueBuilder = new StringBuilder(); if (borderWidthValue != null) { cssValueBuilder.append(borderWidthValue).append(' '); } if (borderStyle != null) { cssValueBuilder.append(borderStyle.getCssValue()).append(' '); } if (borderColorCssValues != null) { cssValueBuilder.append(borderColorCssValues.getValue()).append(' '); } final String trimmedCssValue = StringBuilderUtil .getTrimmedString(cssValueBuilder).toString(); cssValue = trimmedCssValue.isEmpty() ? INHERIT : trimmedCssValue; this.borderStyle = borderStyle; if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } return this; }
java
{ "resource": "" }
q168268
Id.setValue
validation
public void setValue(final UUID uuid) { if (uuid != null) { super.setAttributeValue(uuid.toString()); this.uuid = uuid; } }
java
{ "resource": "" }
q168269
ByteBufferUtil.merge
validation
public static ByteBuffer merge(final ByteBuffer... dataArray) { int totalCapacity = 0; for (final ByteBuffer data : dataArray) { totalCapacity += data.capacity(); } final ByteBuffer wholeData = ByteBuffer.allocate(totalCapacity); for (final ByteBuffer data : dataArray) { wholeData.put(data); } wholeData.flip(); return wholeData; }
java
{ "resource": "" }
q168270
Style.removeAllCssProperties
validation
public void removeAllCssProperties() { final long stamp = lock.writeLock(); try { cssProperties.clear(); abstractCssPropertyClassObjects.clear(); super.removeAllFromAttributeValueMap(); } finally { lock.unlockWrite(stamp); } }
java
{ "resource": "" }
q168271
Style.contains
validation
public boolean contains(final CssProperty cssProperty) { final long stamp = lock.readLock(); try { return cssProperties.contains(cssProperty); } finally { lock.unlockRead(stamp); } }
java
{ "resource": "" }
q168272
AbstractCssFileBlock.getCssPropertiesAsMap
validation
Map<String, CssProperty> getCssPropertiesAsMap(final boolean rebuild) { if (rebuild || !loadedOnce) { synchronized (cssProperties) { if (rebuild || !loadedOnce) { cssProperties.clear(); load(cssProperties); loadedOnce = true; setModified(true); } } } return cssPropertiesAsMap; }
java
{ "resource": "" }
q168273
TagRepository.findTagsByAttribute
validation
public Collection<AbstractHtml> findTagsByAttribute( final AbstractAttribute attribute) throws NullValueException { if (attribute == null) { throw new NullValueException("attribute cannot be null"); } final Collection<AbstractHtml> tags = new HashSet<>(); for (final AbstractHtml ownerTag : attribute.getOwnerTags()) { if (browserPage.contains(ownerTag)) { tags.add(ownerTag); } } return tags; }
java
{ "resource": "" }
q168274
TagRepository.findOneTagByAttribute
validation
public AbstractHtml findOneTagByAttribute( final AbstractAttribute attribute) { if (attribute == null) { throw new NullValueException("attribute cannot be null"); } for (final AbstractHtml ownerTag : attribute.getOwnerTags()) { if (browserPage.contains(ownerTag)) { return ownerTag; } } return null; }
java
{ "resource": "" }
q168275
TagRepository.findAllAttributes
validation
public Collection<AbstractAttribute> findAllAttributes( final boolean parallel) { final Collection<Lock> locks = getReadLocks(rootTags); for (final Lock lock : locks) { lock.lock(); } try { return buildAllAttributesStream(parallel) .collect(Collectors.toSet()); } finally { for (final Lock lock : locks) { lock.unlock(); } } }
java
{ "resource": "" }
q168276
TagRepository.buildAllAttributesStream
validation
public Stream<AbstractAttribute> buildAllAttributesStream( final boolean parallel) { final Stream<AbstractAttribute> attributesStream = buildAllTagsStream( parallel).filter(tag -> tag.getAttributes() != null) .map(tag -> { return tag.getAttributes(); }).flatMap(attributes -> attributes.stream()); return attributesStream; }
java
{ "resource": "" }
q168277
TagRepository.findAllAttributes
validation
public static Collection<AbstractAttribute> findAllAttributes( final boolean parallel, final AbstractHtml... fromTags) throws NullValueException { if (fromTags == null) { throw new NullValueException("fromTags cannot be null"); } final Collection<Lock> locks = getReadLocks(fromTags); for (final Lock lock : locks) { lock.lock(); } try { return getAllNestedChildrenIncludingParent(parallel, fromTags) .filter(tag -> tag.getAttributes() != null).map(tag -> { return tag.getAttributes(); }).flatMap(attributes -> attributes.stream()) .collect(Collectors.toSet()); } finally { for (final Lock lock : locks) { lock.unlock(); } } }
java
{ "resource": "" }
q168278
TagRepository.exists
validation
public boolean exists(final AbstractHtml tag) throws NullValueException, InvalidTagException { if (tag == null) { throw new NullValueException("tag cannot be null"); } if (NoTag.class.isAssignableFrom(tag.getClass())) { throw new InvalidTagException( "classes like NoTag.class cannot be used to find tags as it's not a logical tag in behaviour."); } return browserPage.contains(tag); }
java
{ "resource": "" }
q168279
TagRepository.exists
validation
public boolean exists(final AbstractAttribute attribute) throws NullValueException { if (attribute == null) { throw new NullValueException("attribute cannot be null"); } for (final AbstractHtml ownerTag : attribute.getOwnerTags()) { if (browserPage.contains(ownerTag)) { return true; } } return false; }
java
{ "resource": "" }
q168280
TagRepository.buildAllAttributesStream
validation
public static Stream<AbstractAttribute> buildAllAttributesStream( final boolean parallel, final AbstractHtml... fromTags) { final Stream<AbstractAttribute> attributesStream = getAllNestedChildrenIncludingParent( parallel, fromTags).filter(tag -> tag.getAttributes() != null) .map(tag -> { return tag.getAttributes(); }).flatMap(attributes -> attributes.stream()); return attributesStream; }
java
{ "resource": "" }
q168281
TextArea.getChildText
validation
public String getChildText() { final List<AbstractHtml> children = getChildren(); if (children.size() > 0) { final StringBuilder builder = new StringBuilder(); for (final AbstractHtml child : children) { builder.append(child.toHtmlString()); } return builder.toString(); } return ""; }
java
{ "resource": "" }
q168282
WffBinaryMessageOutputStreamer.writeByChunk
validation
private void writeByChunk(final byte[] bytes) throws IOException { final int chunkSize = this.chunkSize; if (bytes.length == 0) { return; } if (chunkSize < bytes.length && chunkSize > 0) { int remaining = bytes.length; int offset = 0; while (remaining > 0) { if (chunkSize < remaining) { os.write(bytes, offset, chunkSize); remaining -= chunkSize; offset += chunkSize; } else { os.write(bytes, offset, remaining); remaining = 0; } } } else { os.write(bytes); } }
java
{ "resource": "" }
q168283
EmbeddedTomcat.setContextPath
validation
public EmbeddedTomcat setContextPath(String contextPath) { if (contextPath == null || !contextPath.equals("") && !contextPath.startsWith("/")) { throw new IllegalArgumentException( "contextPath must be the empty string \"\" or a path starting with /"); } this.contextPath = contextPath; return this; }
java
{ "resource": "" }
q168284
EmbeddedTomcat.setContextFile
validation
public EmbeddedTomcat setContextFile(String contextFile) { try { this.contextFileURL = new File(contextFile).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } return this; }
java
{ "resource": "" }
q168285
EmbeddedTomcat.addContextEnvironmentAndResourceFromFile
validation
@Deprecated public EmbeddedTomcat addContextEnvironmentAndResourceFromFile(String contextFile) { try { setContextFile(new File(contextFile).toURI().toURL()); } catch (MalformedURLException e) { throw new RuntimeException(e); } return this; }
java
{ "resource": "" }
q168286
Content.filter
validation
public static <T> Filter<T> filter(final Path.Filter filter, final Content.Type<T> contentType) { return new Filter<T>() { @Override public boolean matches(Path.ID id, Content.Type<T> ct) { return ct == contentType && filter.matches(id); } @Override public boolean matchesSubpath(Path.ID id) { return filter.matchesSubpath(id); } @Override public String toString() { return filter.toString(); } }; }
java
{ "resource": "" }
q168287
Content.or
validation
public static <T> Filter<T> or(final Filter<T> f1, final Filter<T> f2) { return new Filter<T>() { @Override public boolean matches(Path.ID id, Content.Type<T> ct) { return f1.matches(id, ct) || f2.matches(id, ct); } @Override public boolean matchesSubpath(Path.ID id) { return f1.matchesSubpath(id) || f2.matchesSubpath(id); } @Override public String toString() { return f1.toString() + "|" + f2.toString(); } }; }
java
{ "resource": "" }
q168288
ConfigFileParser.checkNotEof
validation
private void checkNotEof() { skipWhiteSpace(); if (index >= tokens.size()) { if (index > 0) { syntaxError("unexpected end-of-file", tokens.get(index - 1)); } else { // I believe this is actually dead-code, since checkNotEof() // won't be called before at least one token is matched. throw new SyntacticException("unexpected end-of-file", file.getEntry(), null); } } }
java
{ "resource": "" }
q168289
ConfigFileParser.isLineSpace
validation
private boolean isLineSpace(Token token) { return token.kind == Token.Kind.Indent || token.kind == Token.Kind.LineComment; }
java
{ "resource": "" }
q168290
ConfigFileParser.parseString
validation
protected String parseString(String v) { /* * Parsing a string requires several steps to be taken. First, we need * to strip quotes from the ends of the string. */ v = v.substring(1, v.length() - 1); StringBuffer result = new StringBuffer(); // Second, step through the string and replace escaped characters for (int i = 0; i < v.length(); i++) { if (v.charAt(i) == '\\') { if (v.length() <= i + 1) { throw new RuntimeException("unexpected end-of-string"); } else { char replace = 0; int len = 2; switch (v.charAt(i + 1)) { case 'b': replace = '\b'; break; case 't': replace = '\t'; break; case 'n': replace = '\n'; break; case 'f': replace = '\f'; break; case 'r': replace = '\r'; break; case '"': replace = '\"'; break; case '\'': replace = '\''; break; case '\\': replace = '\\'; break; case 'u': len = 6; // unicode escapes are six digits long, // including "slash u" String unicode = v.substring(i + 2, i + 6); replace = (char) Integer.parseInt(unicode, 16); // unicode i = i + 5; break; default: throw new RuntimeException("unknown escape character"); } result = result.append(replace); i = i + 1; } } else { result = result.append(v.charAt(i)); } } return result.toString(); }
java
{ "resource": "" }
q168291
AbstractLexer.scan
validation
public List<Token> scan() throws Error { ArrayList<Token> tokens = new ArrayList<>(); int pos = 0; while (pos < input.length()) { int start = pos; for (int i = 0; i != rules.length; ++i) { Rule rule = rules[i]; int left = input.length() - pos; if (left >= rule.lookahead()) { Token t = rule.match(input, pos); if (t != null) { tokens.add(t); pos = pos + t.text.length(); break; // restart rule application loop } } } if(pos == start) { throw new Error("unrecognised token encountered (" + input.charAt(pos) + ")",pos); } } return tokens; }
java
{ "resource": "" }
q168292
CommandParser.parse
validation
protected Command.Template parse(Command.Descriptor root, String[] args, int index) { ArrayList<Command.Option> options = new ArrayList<>(); ArrayList<String> arguments = new ArrayList<>(); // Command.Template sub = null; while (index < args.length) { String arg = args[index]; if (isLongOption(arg)) { options.add(parseLongOption(root, args[index])); } else if (isCommand(arg, root.getCommands())) { Command.Descriptor cmd = getCommandDescriptor(arg, root.getCommands()); sub = parse(cmd, args, index + 1); break; } else { arguments.add(arg); } index = index + 1; } // Command.Options optionMap = new OptionsMap(options, root.getOptionDescriptors()); // return new ConcreteTemplate(root, optionMap, arguments, sub); }
java
{ "resource": "" }
q168293
CommandParser.parseData
validation
private static Object parseData(String str) { if (str.equals("true")) { return true; } else if (str.equals("false")) { return false; } else if (Character.isDigit(str.charAt(0))) { // number return Integer.parseInt(str); } else { return str; } }
java
{ "resource": "" }
q168294
Help.printUsage
validation
protected void printUsage() { List<Command.Descriptor> descriptors = project.getParent().getCommandDescriptors(); // out.println("usage: wy [--verbose] command [<options>] [<args>]"); out.println(); int maxWidth = determineCommandNameWidth(descriptors); out.println("Commands:"); for (Command.Descriptor d : descriptors) { out.print(" "); out.print(rightPad(d.getName(), maxWidth)); out.println(" " + d.getDescription()); } out.println(); out.println("Run `wy help COMMAND` for more information on a command"); }
java
{ "resource": "" }
q168295
Help.determineCommandNameWidth
validation
private static int determineCommandNameWidth(List<Command.Descriptor> descriptors) { int max = 0; for (Command.Descriptor d : descriptors) { max = Math.max(max, d.getName().length()); } return max; }
java
{ "resource": "" }
q168296
Install.createZipFile
validation
private ZipFile createZipFile(List<Path.Entry<?>> files) throws IOException { // The set of known paths HashSet<Path.ID> paths = new HashSet<>(); // The zip file we're creating ZipFile zf = new ZipFile(); // Add each file to zip file for (int i = 0; i != files.size(); ++i) { Path.Entry<?> file = files.get(i); // Extract path addPaths(file.id().parent(),paths,zf); // Construct filename for given entry String filename = file.id().toString() + "." + file.contentType().getSuffix(); // Extract bytes representing entry byte[] contents = readFileContents(file); zf.add(new ZipEntry(filename), contents); } // return zf; }
java
{ "resource": "" }
q168297
Install.readFileContents
validation
private byte[] readFileContents(Path.Entry<?> file) throws IOException { InputStream in = file.inputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; // Read bytes in max 1024 chunks byte[] data = new byte[1024]; // Read all bytes from the input stream while ((nRead = in.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } // Done buffer.flush(); return buffer.toByteArray(); }
java
{ "resource": "" }
q168298
Install.createFilter
validation
private Content.Filter createFilter(String filter) { String[] split = filter.split("\\."); // Content.Type contentType = getContentType(split[1]); // return Content.filter(split[0], contentType); }
java
{ "resource": "" }
q168299
BinaryOutputStream.write
validation
@Override public void write(int i) throws IOException { if(count == 0) { output.write(i & 0xFF); } else { write_un(i & 0xFF,8); } }
java
{ "resource": "" }