code
stringlengths
73
34.1k
label
stringclasses
1 value
public TimezoneOffsetFrom setTimezoneOffsetFrom(UtcOffset offset) { TimezoneOffsetFrom prop = new TimezoneOffsetFrom(offset); setTimezoneOffsetFrom(prop); return prop; }
java
public TimezoneName addTimezoneName(String timezoneName) { TimezoneName prop = new TimezoneName(timezoneName); addTimezoneName(prop); return prop; }
java
private static String getCidUriValue(String uri) { int colon = uri.indexOf(':'); if (colon == 3) { String scheme = uri.substring(0, colon); return "cid".equalsIgnoreCase(scheme) ? uri.substring(colon + 1) : null; } if (uri.length() > 0 && uri.charAt(0) == '<' && uri.charAt(uri.length() - 1) == '>') { ...
java
public <T extends ICalProperty> T getProperty(Class<T> clazz) { return clazz.cast(properties.first(clazz)); }
java
public List<ICalProperty> setProperty(ICalProperty property) { return properties.replace(property.getClass(), property); }
java
public <T extends ICalProperty> List<T> setProperty(Class<T> clazz, T property) { List<ICalProperty> replaced = properties.replace(clazz, property); return castList(replaced, clazz); }
java
public <T extends ICalProperty> boolean removeProperty(T property) { return properties.remove(property.getClass(), property); }
java
public <T extends ICalProperty> List<T> removeProperties(Class<T> clazz) { List<ICalProperty> removed = properties.removeAll(clazz); return castList(removed, clazz); }
java
public <T extends ICalComponent> boolean removeComponent(T component) { return components.remove(component.getClass(), component); }
java
public <T extends ICalComponent> List<T> removeComponents(Class<T> clazz) { List<ICalComponent> removed = components.removeAll(clazz); return castList(removed, clazz); }
java
public RawProperty getExperimentalProperty(String name) { for (RawProperty raw : getExperimentalProperties()) { if (raw.getName().equalsIgnoreCase(name)) { return raw; } } return null; }
java
public List<RawProperty> getExperimentalProperties(String name) { /* * Note: The returned list is not backed by the parent component because * this would allow RawProperty objects without the specified name to be * added to the list. */ List<RawProperty> toReturn = new ArrayList<RawProperty>(); for (R...
java
public List<RawProperty> removeExperimentalProperties(String name) { List<RawProperty> all = getExperimentalProperties(); List<RawProperty> toRemove = new ArrayList<RawProperty>(); for (RawProperty property : all) { if (property.getName().equalsIgnoreCase(name)) { toRemove.add(property); } } all.re...
java
public <T extends ICalComponent> T getComponent(Class<T> clazz) { return clazz.cast(components.first(clazz)); }
java
public <T extends ICalComponent> List<T> getComponents(Class<T> clazz) { return new ICalComponentList<T>(clazz); }
java
public List<ICalComponent> setComponent(ICalComponent component) { return components.replace(component.getClass(), component); }
java
public <T extends ICalComponent> List<T> setComponent(Class<T> clazz, T component) { List<ICalComponent> replaced = components.replace(clazz, component); return castList(replaced, clazz); }
java
public RawComponent getExperimentalComponent(String name) { for (RawComponent component : getExperimentalComponents()) { if (component.getName().equalsIgnoreCase(name)) { return component; } } return null; }
java
public List<RawComponent> getExperimentalComponents(String name) { /* * Note: The returned list is not backed by the parent component because * this would allow RawComponent objects without the specified name to * be added to the list. */ List<RawComponent> toReturn = new ArrayList<RawComponent>(); fo...
java
public RawComponent addExperimentalComponent(String name) { RawComponent raw = new RawComponent(name); addComponent(raw); return raw; }
java
public List<RawComponent> removeExperimentalComponents(String name) { List<RawComponent> all = getExperimentalComponents(); List<RawComponent> toRemove = new ArrayList<RawComponent>(); for (RawComponent property : all) { if (property.getName().equalsIgnoreCase(name)) { toRemove.add(property); } } a...
java
protected void checkRequiredCardinality(List<ValidationWarning> warnings, Class<? extends ICalProperty>... classes) { for (Class<? extends ICalProperty> clazz : classes) { List<? extends ICalProperty> props = getProperties(clazz); if (props.isEmpty()) { warnings.add(new ValidationWarning(2, clazz.getSimple...
java
private static <T> List<T> castList(List<?> list, Class<T> castTo) { List<T> casted = new ArrayList<T>(list.size()); for (Object object : list) { casted.add(castTo.cast(object)); } return Collections.unmodifiableList(casted); }
java
public final T parseText(String value, ICalDataType dataType, ICalParameters parameters, ParseContext context) { T property = _parseText(value, dataType, parameters, context); property.setParameters(parameters); return property; }
java
private static String jcalValueToString(JCalValue value) { List<JsonValue> values = value.getValues(); if (values.size() > 1) { List<String> multi = value.asMulti(); if (!multi.isEmpty()) { return VObjectPropertyValues.writeList(multi); } } if (!values.isEmpty() && values.get(0).getArray() != null...
java
protected static DateWriter date(Date date) { return date((date == null) ? null : new ICalDate(date)); }
java
protected static ICalParameters handleTzidParameter(ICalProperty property, boolean hasTime, WriteContext context) { ICalParameters parameters = property.getParameters(); //date values don't have timezones if (!hasTime) { return parameters; } //vCal doesn't use the TZID parameter if (context.getVersion(...
java
public ICalComponentScribe<? extends ICalComponent> getComponentScribe(String componentName, ICalVersion version) { componentName = componentName.toUpperCase(); ICalComponentScribe<? extends ICalComponent> scribe = experimentalCompByName.get(componentName); if (scribe == null) { scribe = standardCompByName.ge...
java
public ICalPropertyScribe<? extends ICalProperty> getPropertyScribe(String propertyName, ICalVersion version) { propertyName = propertyName.toUpperCase(); String key = propertyNameKey(propertyName, version); ICalPropertyScribe<? extends ICalProperty> scribe = experimentalPropByName.get(key); if (scribe == null...
java
public ICalComponentScribe<? extends ICalComponent> getComponentScribe(Class<? extends ICalComponent> clazz) { ICalComponentScribe<? extends ICalComponent> scribe = experimentalCompByClass.get(clazz); if (scribe != null) { return scribe; } return standardCompByClass.get(clazz); }
java
public ICalPropertyScribe<? extends ICalProperty> getPropertyScribe(Class<? extends ICalProperty> clazz) { ICalPropertyScribe<? extends ICalProperty> scribe = experimentalPropByClass.get(clazz); if (scribe != null) { return scribe; } return standardPropByClass.get(clazz); }
java
public ICalComponentScribe<? extends ICalComponent> getComponentScribe(ICalComponent component) { if (component instanceof RawComponent) { RawComponent raw = (RawComponent) component; return new RawComponentScribe(raw.getName()); } return getComponentScribe(component.getClass()); }
java
public ICalPropertyScribe<? extends ICalProperty> getPropertyScribe(ICalProperty property) { if (property instanceof RawProperty) { RawProperty raw = (RawProperty) property; return new RawPropertyScribe(raw.getName()); } return getPropertyScribe(property.getClass()); }
java
public ICalPropertyScribe<? extends ICalProperty> getPropertyScribe(QName qname) { ICalPropertyScribe<? extends ICalProperty> scribe = experimentalPropByQName.get(qname); if (scribe == null) { scribe = standardPropByQName.get(qname); } if (scribe == null || !scribe.getSupportedVersions().contains(ICalVersio...
java
public void unregister(ICalComponentScribe<? extends ICalComponent> scribe) { experimentalCompByName.remove(scribe.getComponentName().toUpperCase()); experimentalCompByClass.remove(scribe.getComponentClass()); }
java
public void unregister(ICalPropertyScribe<? extends ICalProperty> scribe) { for (ICalVersion version : ICalVersion.values()) { experimentalPropByName.remove(propertyNameKey(scribe, version)); } experimentalPropByClass.remove(scribe.getPropertyClass()); experimentalPropByQName.remove(scribe.getQName()); }
java
private static Date determineStartDate(VAlarm valarm, ICalComponent parent) { Trigger trigger = valarm.getTrigger(); if (trigger == null) { return null; } Date triggerStart = trigger.getDate(); if (triggerStart != null) { return triggerStart; } Duration triggerDuration = trigger.getDuration(); i...
java
static int[] uniquify(int[] ints) { IntSet iset = new IntSet(); for (int i : ints) { iset.add(i); } return iset.toIntArray(); }
java
static int countInPeriod(DayOfWeek dow, DayOfWeek dow0, int nDays) { //two cases: // (1a) dow >= dow0: count === (nDays - (dow - dow0)) / 7 // (1b) dow < dow0: count === (nDays - (7 - dow0 - dow)) / 7 if (dow.getCalendarConstant() >= dow0.getCalendarConstant()) { return 1 + ((nDays - (dow.getCalendarCon...
java
private DateValue generateInstance() { try { do { if (!instanceGenerator.generate(builder)) { return null; } DateValue dUtc = dtStart instanceof TimeValue ? TimeUtils.toUtc(builder.toDateTime(), tzid) : builder.toDate(); if (dUtc.compareTo(lastUtc_) > 0) { return dUtc; } } while (t...
java
public void setTimezone(ICalProperty property, TimezoneAssignment timezone) { if (timezone == null) { TimezoneAssignment existing = propertyTimezones.remove(property); if (existing != null && existing != defaultTimezone && !propertyTimezones.values().contains(existing)) { assignments.remove(existing); } ...
java
public boolean isFloating(ICalProperty property) { if (containsIdentity(floatingProperties, property)) { return true; } if (propertyTimezones.containsKey(property)) { return false; } return globalFloatingTime; }
java
private static <T> void removeIdentity(List<T> list, T object) { Iterator<T> it = list.iterator(); while (it.hasNext()) { if (object == it.next()) { it.remove(); } } }
java
private static <T> boolean containsIdentity(List<T> list, T object) { for (T item : list) { if (item == object) { return true; } } return false; }
java
public ChainingXmlWriter register(String parameterName, ICalDataType dataType) { parameterDataTypes.put(parameterName, dataType); return this; }
java
public void setScribeIndex(ScribeIndex index) { this.index = index; serializer.setScribeIndex(index); deserializer.setScribeIndex(index); }
java
public static JCalValue multi(List<?> values) { List<JsonValue> multiValues = new ArrayList<JsonValue>(values.size()); for (Object value : values) { multiValues.add(new JsonValue(value)); } return new JCalValue(multiValues); }
java
public static JCalValue structured(List<List<?>> values) { List<JsonValue> array = new ArrayList<JsonValue>(values.size()); for (List<?> list : values) { if (list.isEmpty()) { array.add(new JsonValue("")); continue; } if (list.size() == 1) { Object value = list.get(0); if (value == null) ...
java
public static JCalValue object(ListMultimap<String, Object> value) { Map<String, JsonValue> object = new LinkedHashMap<String, JsonValue>(); for (Map.Entry<String, List<Object>> entry : value) { String key = entry.getKey(); List<Object> list = entry.getValue(); JsonValue v; if (list.size() == 1) { ...
java
public String asSingle() { if (values.isEmpty()) { return ""; } JsonValue first = values.get(0); if (first.isNull()) { return ""; } Object obj = first.getValue(); if (obj != null) { return obj.toString(); } //get the first element of the array List<JsonValue> array = first.getArray(); ...
java
public List<List<String>> asStructured() { if (values.isEmpty()) { return Collections.emptyList(); } JsonValue first = values.get(0); //["request-status", {}, "text", ["2.0", "Success"] ] List<JsonValue> array = first.getArray(); if (array != null) { List<List<String>> components = new ArrayList<Lis...
java
public List<String> asMulti() { if (values.isEmpty()) { return Collections.emptyList(); } List<String> multi = new ArrayList<String>(values.size()); for (JsonValue value : values) { if (value.isNull()) { multi.add(""); continue; } Object obj = value.getValue(); if (obj != null) { mu...
java
public ListMultimap<String, String> asObject() { if (values.isEmpty()) { return new ListMultimap<String, String>(0); } Map<String, JsonValue> map = values.get(0).getObject(); if (map == null) { return new ListMultimap<String, String>(0); } ListMultimap<String, String> values = new ListMultimap<Strin...
java
public static DateTimeComponents parse(String dateString, Boolean hasTime) { Matcher m = regex.matcher(dateString); if (!m.find()) { throw Messages.INSTANCE.getIllegalArgumentException(19, dateString); } int i = 1; int year = Integer.parseInt(m.group(i++)); int month = Integer.parseInt(m.group(i++)); ...
java
public static RecurrenceIterator createRecurrenceIterator(Collection<? extends DateValue> dates) { DateValue[] datesArray = dates.toArray(new DateValue[0]); return new RDateIteratorImpl(datesArray); }
java
public static RecurrenceIterable createRecurrenceIterable(final Recurrence rrule, final DateValue dtStart, final TimeZone tzid) { return new RecurrenceIterable() { public RecurrenceIterator iterator() { return createRecurrenceIterator(rrule, dtStart, tzid); } }; }
java
public static RecurrenceIterator join(RecurrenceIterator first, RecurrenceIterator... rest) { List<RecurrenceIterator> all = new ArrayList<RecurrenceIterator>(); all.add(first); all.addAll(Arrays.asList(rest)); return new CompoundIteratorImpl(all, Collections.<RecurrenceIterator> emptyList()); }
java
public static Duration parse(String value) { /* * Implementation note: Regular expressions are not used to improve * performance. */ if (value.length() == 0) { throw parseError(value); } int index = 0; char first = value.charAt(index); boolean prior = (first == '-'); if (first == '-' || firs...
java
public static Duration diff(Date start, Date end) { return fromMillis(end.getTime() - start.getTime()); }
java
public static Duration fromMillis(long milliseconds) { Duration.Builder builder = builder(); if (milliseconds < 0) { builder.prior(true); milliseconds *= -1; } int seconds = (int) (milliseconds / 1000); Integer weeks = seconds / (60 * 60 * 24 * 7); if (weeks > 0) { builder.weeks(weeks); } se...
java
public long toMillis() { long totalSeconds = 0; if (weeks != null) { totalSeconds += 60L * 60 * 24 * 7 * weeks; } if (days != null) { totalSeconds += 60L * 60 * 24 * days; } if (hours != null) { totalSeconds += 60L * 60 * hours; } if (minutes != null) { totalSeconds += 60L * minutes; } ...
java
private static DateValue[] removeDuplicates(DateValue[] dates) { int k = 0; for (int i = 1; i < dates.length; ++i) { if (!dates[i].equals(dates[k])) { dates[++k] = dates[i]; } } if (++k < dates.length) { DateValue[] uniqueDates = new DateValue[k]; System.arraycopy(dates, 0, uniqueDates, 0, k); ...
java
public T emptyInstance() { T component = _newInstance(); //remove any properties/components that were created in the constructor component.getProperties().clear(); component.getComponents().clear(); return component; }
java
public List<ICalComponent> getComponents(T component) { return new ArrayList<ICalComponent>(component.getComponents().values()); }
java
public List<ICalProperty> getProperties(T component) { return new ArrayList<ICalProperty>(component.getProperties().values()); }
java
public void registerParameterDataType(String parameterName, ICalDataType dataType) { parameterName = parameterName.toLowerCase(); if (dataType == null) { parameterDataTypes.remove(parameterName); } else { parameterDataTypes.put(parameterName, dataType); } }
java
public static void premain(String agentArgs, Instrumentation inst) { // How do agent args work? http://stackoverflow.com/questions/23287228/how-do-i-pass-arguments-to-a-java-instrumentation-agent // e.g. java -javaagent:/path/to/agent.jar=argumentstring MarkerType markerType = MarkerTyp...
java
public static StorageSizes computeSizes(Frame<BasicValue> frame, int offset, int length) { Validate.notNull(frame); Validate.isTrue(offset >= 0); Validate.isTrue(length >= 0); Validate.isTrue(offset < frame.getStackSize()); Validate.isTrue(offset + length <= frame.getStackSize())...
java
public static InsnList jumpTo(LabelNode labelNode) { Validate.notNull(labelNode); InsnList ret = new InsnList(); ret.add(new JumpInsnNode(Opcodes.GOTO, labelNode)); return ret; }
java
public static InsnList addLabel(LabelNode labelNode) { Validate.notNull(labelNode); InsnList ret = new InsnList(); ret.add(labelNode); return ret; }
java
public static InsnList lineNumber(int num) { Validate.isTrue(num >= 0); InsnList ret = new InsnList(); LabelNode labelNode = new LabelNode(); ret.add(labelNode); ret.add(new LineNumberNode(num, labelNode)); return ret; }
java
public static InsnList pop() { InsnList ret = new InsnList(); ret.add(new InsnNode(Opcodes.POP)); return ret; }
java
public static InsnList monitorEnter() { InsnList ret = new InsnList(); ret.add(new InsnNode(Opcodes.MONITORENTER)); return ret; }
java
public static InsnList monitorExit() { InsnList ret = new InsnList(); ret.add(new InsnNode(Opcodes.MONITOREXIT)); return ret; }
java
public static InsnList loadIntConst(int i) { InsnList ret = new InsnList(); ret.add(new LdcInsnNode(i)); return ret; }
java
public static InsnList loadStringConst(String s) { Validate.notNull(s); InsnList ret = new InsnList(); ret.add(new LdcInsnNode(s)); return ret; }
java
public static InsnList loadNull() { InsnList ret = new InsnList(); ret.add(new InsnNode(Opcodes.ACONST_NULL)); return ret; }
java
public static InsnList loadVar(Variable variable) { Validate.notNull(variable); InsnList ret = new InsnList(); switch (variable.getType().getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: ...
java
public static InsnList saveVar(Variable variable) { Validate.notNull(variable); InsnList ret = new InsnList(); switch (variable.getType().getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: ...
java
public static InsnList createNewObjectArray(InsnList size) { Validate.notNull(size); InsnList ret = new InsnList(); ret.add(size); ret.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object")); return ret; }
java
public static InsnList loadArrayLength(InsnList arrayRef) { Validate.notNull(arrayRef); InsnList ret = new InsnList(); ret.add(arrayRef); ret.add(new InsnNode(Opcodes.ARRAYLENGTH)); return ret; }
java
public static InsnList addIntegers(InsnList lhs, InsnList rhs) { Validate.notNull(lhs); Validate.notNull(rhs); InsnList ret = new InsnList(); ret.add(lhs); ret.add(rhs); ret.add(new InsnNode(Opcodes.IADD)); return ret; }
java
public static InsnList ifIntegersEqual(InsnList lhs, InsnList rhs, InsnList action) { Validate.notNull(lhs); Validate.notNull(rhs); Validate.notNull(action); InsnList ret = new InsnList(); LabelNode notEqualLabelNode = new LabelNode(); ...
java
public static InsnList forEach(Variable counterVar, Variable arrayLenVar, InsnList array, InsnList action) { Validate.notNull(counterVar); Validate.notNull(arrayLenVar); Validate.notNull(array); Validate.notNull(action); Validate.isTrue(counterVar.getType().equals(Type.INT_TYPE))...
java
public static InsnList combineObjectArrays(Variable destArrayVar, Variable firstArrayVar, Variable secondArrayVar) { Validate.notNull(destArrayVar); Validate.notNull(firstArrayVar); Validate.notNull(secondArrayVar); Validate.isTrue(destArrayVar.getType().equals(Type.getType(Object[].clas...
java
public static InsnList tryCatchBlock(TryCatchBlockNode tryCatchBlockNode, Type exceptionType, InsnList tryInsnList, InsnList catchInsnList) { Validate.notNull(tryInsnList); // exceptionType can be null Validate.notNull(catchInsnList); if (exceptionType != null) { ...
java
public static InsnList returnValue(Type returnType, InsnList returnValueInsnList) { Validate.notNull(returnType); Validate.isTrue(returnType.getSort() != Type.METHOD); InsnList ret = new InsnList(); ret.add(returnValueInsnList); switch (returnType.getSort()) { ...
java
protected final void instrumentPath(Log log, List<String> classpath, File path) throws MojoExecutionException { try { Instrumenter instrumenter = getInstrumenter(log, classpath); InstrumentationSettings settings = new InstrumentationSettings(markerType, debugMode, autoSeriali...
java
private static byte[] dumpBytecode(MethodNode methodNode) { // Calculate label offsets -- required for hash calculation // we only care about where the labels are in relation to the opcode instructions -- we don't care about things like // LocalVariableNode or other ancillary data because th...
java
public static Type getReturnTypeOfInvocation(AbstractInsnNode invokeNode) { Validate.notNull(invokeNode); if (invokeNode instanceof MethodInsnNode) { MethodInsnNode methodInsnNode = (MethodInsnNode) invokeNode; Type methodType = Type.getType(methodInsnNode.desc); ret...
java
public void addIndividual(String className, ClassInformation classInformation) { Validate.notNull(className); Validate.notNull(classInformation); Validate.isTrue(!hierarchyMap.containsKey(className)); hierarchyMap.put(className, classInformation); }
java
public void addClasspath(List<File> classpath) throws IOException { Validate.notNull(classpath); Validate.noNullElements(classpath); for (File classpathElement : classpath) { if (classpathElement.isFile()) { addJar(classpathElement); } else if (classpathE...
java
private static InsnList popMethodResult(AbstractInsnNode invokeInsnNode) { Validate.notNull(invokeInsnNode); Type returnType = getReturnTypeOfInvocation(invokeInsnNode); InsnList ret = new InsnList(); switch (returnType.getSort()) { case Type.LONG: ...
java
public void detail(MethodNode methodNode, MethodAttributes attrs, StringBuilder output) { Validate.notNull(methodNode); Validate.notNull(attrs); Validate.notNull(output); int methodId = attrs.getSignature().getMethodId(); output.append("Class Name: ").append(attrs.getSignature(...
java
@Override protected String getCommonSuperClass(final String type1, final String type2) { Validate.notNull(type1); Validate.notNull(type2); infoRepo.getInformation(type1); LinkedHashSet<String> type1Hierarchy = flattenHierarchy(type1); LinkedHashSet<String> type2Hiera...
java
void validateState() { if (frames == null || coroutine == null) { throw new IllegalStateException("Bad state"); } for (int i = 0; i < frames.length; i++) { if (frames[i] == null) { throw new IllegalStateException("Bad state"); } fr...
java
public static InsnList debugMarker(MarkerType markerType, String text) { Validate.notNull(markerType); Validate.notNull(text); InsnList ret = new InsnList(); switch (markerType) { case NONE: break; case CONSTANT: r...
java
public InstrumentationResult instrument(byte[] input, InstrumentationSettings settings) { Validate.notNull(input); Validate.notNull(settings); Validate.isTrue(input.length > 0); // Read class as tree model -- because we're using SimpleClassNode, JSR blocks get inlined ClassRea...
java
public static List<MethodNode> findMethodsWithName(Collection<MethodNode> methodNodes, String name) { Validate.notNull(methodNodes); Validate.notNull(name); Validate.noNullElements(methodNodes); List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNod...
java
public static List<MethodNode> findStaticMethods(Collection<MethodNode> methodNodes) { Validate.notNull(methodNodes); Validate.noNullElements(methodNodes); List<MethodNode> ret = new ArrayList<>(); for (MethodNode methodNode : methodNodes) { if ((methodNode....
java