code
stringlengths
73
34.1k
label
stringclasses
1 value
public JSONObject clearIndex(RequestOptions requestOptions) throws AlgoliaException { return client.postRequest("/1/indexes/" + encodedIndexName + "/clear", "", true, false, requestOptions); }
java
public JSONObject setSettings(JSONObject settings, RequestOptions requestOptions) throws AlgoliaException { return setSettings(settings, false, requestOptions); }
java
public JSONObject getApiKey(String key, RequestOptions requestOptions) throws AlgoliaException { return client.getRequest("/1/indexes/" + encodedIndexName + "/keys/" + key, false, requestOptions); }
java
public JSONObject deleteApiKey(String key, RequestOptions requestOptions) throws AlgoliaException { return client.deleteRequest("/1/indexes/" + encodedIndexName + "/keys/" + key, requestOptions); }
java
public JSONObject clearSynonyms(boolean forwardToReplicas, RequestOptions requestOptions) throws AlgoliaException { return client.postRequest("/1/indexes/" + encodedIndexName + "/synonyms/clear?forwardToReplicas=" + forwardToReplicas, "", true, false, requestOptions); }
java
public JSONObject getRule(String objectID, RequestOptions requestOptions) throws AlgoliaException { if (objectID == null || objectID.length() == 0) { throw new AlgoliaException("Invalid objectID"); } try { return client.getRequest("/1/indexes/" + encodedIndexName + "/rules/" + URLEncoder.encode(...
java
public Query setOptionalWords(List<String> words) { StringBuilder builder = new StringBuilder(); for (String word : words) { builder.append(word); builder.append(","); } this.optionalWords = builder.toString(); return this; }
java
static String getFallbackDomain() { int javaVersion = getJavaVersion(); boolean javaHasSNI = javaVersion >= 7; final VersionInfo vi = VersionInfo.loadVersionInfo ("org.apache.http.client", APIClient.class.getClassLoader()); String version = vi.getRelease(); String[] split = version.split("\\....
java
public void setUserAgent(String agent, String agentVersion) { userAgent = String.format("Algolia for Java (%s); JVM (%s); %s (%s)", version, System.getProperty("java.version"), agent, agentVersion); }
java
public void enableRateLimitForward(String adminAPIKey, String endUserIP, String rateLimitAPIKey) { this.forwardAdminAPIKey = adminAPIKey; this.forwardEndUserIP = endUserIP; this.forwardRateLimitAPIKey = rateLimitAPIKey; }
java
public void changeAnimation(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView); final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView); final float prevValue = ...
java
protected long determineBalance(final IntervalTreeNode node) { if (node == null) { return 0L; } return (node.hasLeft() ? node.getLeft().getHeight() : 0) - (node.hasRight() ? node.getRight().getHeight() : 0); }
java
protected void fill(int fromIndex, int endIndex) { fromIndex = fromIndex == -1 ? 0 : fromIndex; endIndex = endIndex == -1 || endIndex > this.timeSeries.length ? this.timeSeries.length : endIndex; final T val; if (applyZero()) { val = zero(); } else { val ...
java
public BucketEndPoints getEndPoints(final int bucketsFromNow) throws IllegalTimePoint { if (currentNowIdx == -1 || now == null) { throw new IllegalTimePoint("The now is not set yet, thus no end-points can be returned"); } return now.move(bucketsFromNow); }
java
public int getBucketSize(final long diffInSeconds) { // convert one unit of this into seconds final long secondsPerBucket = TimeUnit.SECONDS.convert(config.getBucketSize(), config.getTimeUnit()); return (int) Math.ceil((double) diffInSeconds / secondsPerBucket); }
java
public void setNow(final long unixTimeStamp) throws IllegalTimePointMovement { /* * "now" strongly depends on the TimeUnit used for the timeSeries, as * well as the bucketSize. If, e.g., the TimeUnit is MINUTES and the * bucketSize is 5, a unix time stamp representing 01/20/1981 08:0...
java
public SerIterable createIterable(String metaTypeDescription, JodaBeanSer settings, Map<String, Class<?>> knownTypes) { if (metaTypeDescription.equals("Set")) { return set(Object.class, EMPTY_VALUE_TYPES); } if (metaTypeDescription.equals("List")) { return list(Object.cla...
java
public SerIterable createIterable(SerIterable iterable) { List<Class<?>> valueTypeTypes = iterable.valueTypeTypes(); if (valueTypeTypes.size() > 0) { Class<?> valueType = iterable.valueType(); if (NavigableSet.class.isAssignableFrom(valueType)) { return navigableS...
java
public static final SerIterable array(final Class<?> valueType) { final List<Object> list = new ArrayList<>(); return new SerIterable() { @Override public SerIterator iterator() { return array(build(), Object.class, valueType); } @Override ...
java
public static final SerIterator array( final Object[] array, final Class<?> declaredType, final Class<?> valueType) { return new SerIterator() { private int index = -1; @Override public String metaTypeName() { return metaTypeNameBase(valueType); ...
java
private StartElement advanceToStartElement() throws Exception { while (reader.hasNext()) { XMLEvent event = nextEvent("advnc "); if (event.isStartElement()) { return event.asStartElement(); } } throw new IllegalArgumentException("Unexpected end...
java
private String advanceAndParseText() throws Exception { StringBuilder buf = new StringBuilder(); while (reader.hasNext()) { XMLEvent event = nextEvent("text "); if (event.isCharacters()) { buf.append(event.asCharacters().getData()); } else if (event.i...
java
private XMLEvent nextEvent(String location) throws Exception { XMLEvent event = reader.nextEvent(); // System.out.println(location + event.toString().replace('\n', ' ') + " " + event.getClass().getSimpleName()); return event; }
java
public JodaBeanSer withIndent(String indent) { JodaBeanUtils.notNull(indent, "indent"); return new JodaBeanSer(indent, newLine, converter, iteratorFactory, shortTypes, deserializers, includeDerived); }
java
public JodaBeanSer withNewLine(String newLine) { JodaBeanUtils.notNull(newLine, "newLine"); return new JodaBeanSer(indent, newLine, converter, iteratorFactory, shortTypes, deserializers, includeDerived); }
java
public JodaBeanSer withIteratorFactory(SerIteratorFactory iteratorFactory) { JodaBeanUtils.notNull(iteratorFactory, "iteratorFactory"); return new JodaBeanSer(indent, newLine, converter, iteratorFactory, shortTypes, deserializers, includeDerived); }
java
public JodaBeanSer withShortTypes(boolean shortTypes) { return new JodaBeanSer(indent, newLine, converter, iteratorFactory, shortTypes, deserializers, includeDerived); }
java
public boolean isSerialized(MetaProperty<?> prop) { return prop.style().isSerializable() || (prop.style().isDerived() && includeDerived); }
java
public static <P> BasicProperty<P> of(Bean bean, MetaProperty<P> metaProperty) { return new BasicProperty<>(bean, metaProperty); }
java
void writeInt(int value) throws IOException { if ((value & 0xfffffff8) == 0) { output.append((char) (value + 48)); } else { output.append(Integer.toString(value)); } }
java
void writeString(String value) throws IOException { output.append('"'); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); if (ch < 128) { String replace = REPLACE[ch]; if (replace != null) { output.append(rep...
java
void writeArrayItemStart() throws IOException { if (commaState.get(commaDepth)) { output.append(','); if (newLine.length() > 0) { output.append(' '); } } else { commaState.set(commaDepth); } }
java
void writeObjectStart() throws IOException { output.append('{'); currentIndent = currentIndent + indent; commaDepth++; commaState.set(commaDepth, false); }
java
void writeObjectKeyValue(String key, String value) throws IOException { writeObjectKey(key); writeString(value); }
java
void writeObjectEnd() throws IOException { currentIndent = currentIndent.substring(0, currentIndent.length() - indent.length()); if (commaState.get(commaDepth)) { output.append(newLine); output.append(currentIndent); } output.append('}'); commaDepth--; ...
java
public static Object wrapValue(MetaProperty<?> metaProp, Class<?> beanType, Object value) { Object[] helpers = OPTIONALS.get(metaProp.propertyType()); if (helpers != null) { try { if (value != null) { value = ((Method) helpers[0]).invoke(null, value); ...
java
public SerDeserializers register(Class<?> type, SerDeserializer deserializer) { deserializers.put(type, deserializer); return this; }
java
public Class<?> decodeType( String typeStr, JodaBeanSer settings, String basePackage, Map<String, Class<?>> knownTypes, Class<?> defaultType) throws ClassNotFoundException { if (lenient) { return SerTypeMapper.decodeType( ...
java
private static void registerFromClasspath( String beanName, String deserName, Map<Class<?>, SerDeserializer> map) throws Exception { Class<? extends Bean> beanClass = Class.forName(beanName).asSubclass(Bean.class); Class<?> deserClass = Class.forName(deserName); Field field = null;...
java
private static SerDeserializer toLenient(SerDeserializer underlying) { return new SerDeserializer() { @Override public MetaBean findMetaBean(Class<?> beanType) { return underlying.findMetaBean(beanType); } @Override public BeanBuilder...
java
private Map<String, Object> dataWritable() { if (data == Collections.EMPTY_MAP) { data = new LinkedHashMap<>(); } return data; }
java
public Map<String, Object> toMap() { if (size() == 0) { return Collections.emptyMap(); } return Collections.unmodifiableMap(new LinkedHashMap<>(data)); }
java
@Deprecated private T build(Constructor<T> constructor, Object[] args) { try { return constructor.newInstance(args); } catch (IllegalArgumentException | IllegalAccessException | InstantiationException ex) { throw new IllegalArgumentException( "Bean cannot...
java
private static String[] fieldNames(Class<?> beanType) { Field[] fields = Stream.of(beanType.getDeclaredFields()) .filter(f -> !Modifier.isStatic(f.getModifiers()) && f.getAnnotation(PropertyDefinition.class) != null) .toArray(Field[]::new); List<String> fieldNames = new A...
java
JsonEvent readEvent() throws IOException { char next = readNext(); // whitespace while (next == ' ' || next == '\t' || next == '\n' || next == '\r') { next = readNext(); } // identify token switch (next) { case '{': return JsonEvent...
java
String acceptObjectKey(JsonEvent event) throws IOException { ensureEvent(event, JsonEvent.STRING); return parseObjectKey(); }
java
JsonEvent acceptObjectSeparator() throws IOException { JsonEvent event = readEvent(); if (event == JsonEvent.COMMA) { return readEvent(); // leniently allow comma before objectEnd } else { return ensureEvent(event, JsonEvent.OBJECT_END); } }
java
JsonEvent acceptArraySeparator() throws IOException { JsonEvent event = readEvent(); if (event == JsonEvent.COMMA) { return readEvent(); // leniently allow comma before arrayEnd } else { return ensureEvent(event, JsonEvent.ARRAY_END); } }
java
public void ensureImport(Class<?> cls) { if (currentImports.contains(cls.getName()) == false) { newImports.add(cls.getName()); } }
java
public String getEffectiveMetaScope() { String scope = beanMetaScope; if ("smart".equals(scope)) { scope = typeScope; } return "package".equals(scope) ? "" : scope + " "; }
java
public String getEffectiveBuilderScope() { String scope = beanBuilderScope; if ("smart".equals(scope)) { scope = typeScope; } return "package".equals(scope) ? "" : scope + " "; }
java
public boolean isConstructorScopeValid() { return "smart".equals(constructorScope) || "private".equals(constructorScope) || "package".equals(constructorScope) || "protected".equals(constructorScope) || "public".equals(constructorScope) || ...
java
public String getEffectiveConstructorScope() { if ("smart".equals(constructorScope)) { return isTypeFinal() ? "private " : "protected "; } else if ("package".equals(constructorScope)) { return ""; } else if ("public@ConstructorProperties".equals(constructorScope)) { ...
java
public void setTypeParts(String[] parts) { this.typeFinal = parts[0] != null; this.typeScope = parts[1]; this.typeFull = parts[2]; this.typeRaw = parts[3]; if (parts[8] != null) { this.typeGenericName = new String[] {parts[4], parts[6], parts[8]}; this.typ...
java
public void setSuperTypeParts(String[] parts) { if (parts.length == 1) { this.root = true; this.immutable = "ImmutableBean".equals(parts[0]); this.superTypeFull = ""; this.superTypeRaw = ""; this.superTypeGeneric = ""; } else { this...
java
public boolean isTypeGenerifiedBy(String type) { if (typeGenericName.length > 2 && typeGenericName[2].equals(type)) { return true; } if (typeGenericName.length > 1 && typeGenericName[1].equals(type)) { return true; } if (typeGenericName.length > 0 && typeG...
java
public static <P> DirectMetaProperty<P> ofReadWrite( MetaBean metaBean, String propertyName, Class<?> declaringType, Class<P> propertyType) { Field field = findField(metaBean, propertyName); return new DirectMetaProperty<>(metaBean, propertyName, declaringType, propertyType, PropertyStyle...
java
public static <P> DirectMetaProperty<P> ofReadOnly( MetaBean metaBean, String propertyName, Class<?> declaringType, Class<P> propertyType) { Field field = findField(metaBean, propertyName); return new DirectMetaProperty<>(metaBean, propertyName, declaringType, propertyType, PropertyStyle....
java
public static <P> DirectMetaProperty<P> ofWriteOnly( MetaBean metaBean, String propertyName, Class<?> declaringType, Class<P> propertyType) { Field field = findField(metaBean, propertyName); return new DirectMetaProperty<>(metaBean, propertyName, declaringType, propertyType, PropertyStyle...
java
public static <P> DirectMetaProperty<P> ofReadOnlyBuildable( MetaBean metaBean, String propertyName, Class<?> declaringType, Class<P> propertyType) { Field field = findField(metaBean, propertyName); return new DirectMetaProperty<>(metaBean, propertyName, declaringType, propertyType, Prope...
java
public static <P> DirectMetaProperty<P> ofDerived( MetaBean metaBean, String propertyName, Class<?> declaringType, Class<P> propertyType) { Field field = findField(metaBean, propertyName); return new DirectMetaProperty<>(metaBean, propertyName, declaringType, propertyType, PropertyStyle.D...
java
public static <P> DirectMetaProperty<P> ofImmutable( MetaBean metaBean, String propertyName, Class<?> declaringType, Class<P> propertyType) { Field field = findField(metaBean, propertyName); return new DirectMetaProperty<>(metaBean, propertyName, declaringType, propertyType, PropertyStyle...
java
public String write(Bean bean, boolean rootType) { StringBuilder buf = new StringBuilder(1024); try { write(bean, rootType, buf); } catch (IOException ex) { throw new IllegalStateException(ex); } return buf.toString(); }
java
void readAll() { try { try { int b = input.read(); while (b >= 0) { readObject(b); b = input.read(); } } finally { input.close(); } } catch (IOException ex) { ...
java
public void resolveType() { if (getTypeStyle() == null) { setTypeStyle(""); } final String fieldType = getFieldType(); String generics = ""; if (fieldType.contains("<")) { generics = fieldType.substring(fieldType.indexOf('<')); } if (getTyp...
java
public void resolveBuilderType() { if (getBuilderTypeStyle() == null) { setBuilderTypeStyle(""); } final String fieldType = getFieldType(); String generics = ""; if (fieldType.contains("<")) { generics = fieldType.substring(fieldType.indexOf('<')); ...
java
public void resolveEqualsHashCodeStyle(File file, int lineIndex) { if (equalsHashCodeStyle.equals("smart")) { equalsHashCodeStyle = (bean.isImmutable() ? "field" : "getter"); } if (equalsHashCodeStyle.equals("omit") || equalsHashCodeStyle.equals("getter") || ...
java
public void resolveToStringStyle(File file, int lineIndex) { if (toStringStyle.equals("smart")) { toStringStyle = (bean.isImmutable() ? "field" : "getter"); } if (toStringStyle.equals("omit") || toStringStyle.equals("getter") || toStringStyle.equals("f...
java
public String getFieldTypeRaw() { int pos = fieldType.indexOf("<"); return (pos < 0 ? fieldType : fieldType.substring(0, pos)); }
java
public void resolveSetterGen(File file, int lineIndex) { if (getSetStyle() == null) { setSetStyle(""); } String style = getSetStyle().replace("\\n", "\n"); String access = "public"; if (style.equals("private")) { style = "smart"; access = "priv...
java
public PropertyStyle getStyle() { if (isDerived()) { return PropertyStyle.DERIVED; } if (getBean().isImmutable()) { return PropertyStyle.IMMUTABLE; } if (getGetStyle().length() > 0 && getSetStyle().length() > 0 && (getSetterGen().isSetterGenerated(this) ||...
java
public String getValidationMethodName() { if (isValidated() == false) { throw new IllegalStateException(); } if (getValidation().equals("notNull") || getValidation().equals("notEmpty") || getValidation().equals("notBlank")) { return "JodaBe...
java
public static boolean equal(Object obj1, Object obj2) { if (obj1 == obj2) { return true; } if (obj1 == null || obj2 == null) { return false; } if (obj1.getClass().isArray()) { return equalsArray(obj1, obj2); } // this does not h...
java
@Override @SuppressWarnings("unchecked") public <P> P get(MetaProperty<P> metaProperty) { return (P) getBuffer().get(metaProperty); }
java
private static Class<?> decodeType0( String className, JodaBeanSer settings, String basePackage, Map<String, Class<?>> knownTypes, Class<?> defaultType) throws ClassNotFoundException { // basic type Class<?> result = BASIC_TYPES_REVERSED.get(c...
java
public Map<String, Object> write(Bean bean) { JodaBeanUtils.notNull(bean, "bean"); return writeBean(bean, bean.getClass()); }
java
void writeBoolean(boolean value) throws IOException { if (value) { output.writeByte(TRUE); } else { output.writeByte(FALSE); } }
java
void writeInt(int value) throws IOException { if (value < MIN_FIX_INT) { // large negative if (value >= Byte.MIN_VALUE) { output.writeByte(SINT_8); output.writeByte((byte) value); } else if (value >= Short.MIN_VALUE) { output.wr...
java
void writeLong(long value) throws IOException { if (value < MIN_FIX_INT) { // large negative if (value >= Byte.MIN_VALUE) { output.writeByte(SINT_8); output.writeByte((byte) value); } else if (value >= Short.MIN_VALUE) { output....
java
void writeBytes(byte[] bytes) throws IOException { int size = bytes.length; if (size < 256) { output.writeByte(BIN_8); output.writeByte(size); } else if (size < 65536) { output.writeByte(BIN_16); output.writeShort(size); } else { ...
java
void writeString(String value) throws IOException { byte[] bytes = toUTF8(value); int size = bytes.length; if (size < 32) { output.writeByte(MIN_FIX_STR + size); } else if (size < 256) { output.writeByte(STR_8); output.writeByte(size); } else i...
java
void writeArrayHeader(int size) throws IOException { if (size < 16) { output.writeByte(MIN_FIX_ARRAY + size); } else if (size < 65536) { output.writeByte(ARRAY_16); output.writeShort(size); } else { output.writeByte(ARRAY_32); output.wr...
java
void writeMapHeader(int size) throws IOException { if (size < 16) { output.writeByte(MIN_FIX_MAP + size); } else if (size < 65536) { output.writeByte(MAP_16); output.writeShort(size); } else { output.writeByte(MAP_32); output.writeInt(s...
java
void writeExtensionByte(int extensionType, int value) throws IOException { output.write(FIX_EXT_1); output.write(extensionType); output.write(value); }
java
void writeExtensionString(int extensionType, String str) throws IOException { byte[] bytes = str.getBytes(UTF_8); if (bytes.length > 256) { throw new IllegalArgumentException("String too long"); } output.write(EXT_8); output.write(bytes.length); output.write(e...
java
void writePositiveExtensionInt(int extensionType, int reference) throws IOException { if (reference < 0) { throw new IllegalArgumentException("Can only serialize positive references: " + reference); } if (reference < 0xFF) { output.write(FIX_EXT_1); output.wri...
java
private void parseClassDescriptions() throws Exception { int refCount = acceptInteger(input.readByte()); if (refCount < 0) { throw new IllegalArgumentException("Invalid binary data: Expected count of references, but was: " + refCount); } refs = new Object[refCount]; ...
java
private ClassInfo parseClassInfo() throws Exception { String className = acceptString(input.readByte()); Class<?> type = SerTypeMapper.decodeType(className, settings, overrideBasePackage, null); int propertyCount = acceptArray(input.readByte()); if (propertyCount < 0) { throw...
java
private Object parseBean(int propertyCount, ClassInfo classInfo) { String propName = ""; if (classInfo.metaProperties.length != propertyCount) { throw new IllegalArgumentException("Invalid binary data: Expected " + classInfo.metaProperties.length + " properties but was: " + propertyCount); ...
java
Class<?> getAndSerializeEffectiveTypeIfRequired(Object value, Class<?> declaredType) throws IOException { Class<?> realType = value.getClass(); Class<?> effectiveType = declaredType; if (declaredType == Object.class) { if (realType != String.class) { effectiveType = s...
java
void writeObjectAsString(Object value, Class<?> effectiveType) throws IOException { String converted = settings.getConverter().convertToString(effectiveType, value); if (converted == null) { throw new IllegalArgumentException("Unable to write because converter returned a null string: " + val...
java
private static MetaBean metaBeanLookup(Class<?> cls) { // handle dynamic beans if (cls == FlexiBean.class) { return new FlexiBean().metaBean(); } else if (cls == MapBean.class) { return new MapBean().metaBean(); } else if (DynamicBean.class.isAssignableFrom(cls)) ...
java
private static List<File> findFiles(final File parent, boolean recurse) { final List<File> result = new ArrayList<>(); if (parent.isDirectory()) { File[] files = parent.listFiles(); files = (files != null ? files : new File[0]); for (File child : files) { ...
java
private File processFile(File file) throws Exception { List<String> original = readFile(file); List<String> content = new ArrayList<>(original); BeanGen gen; try { BeanParser parser = new BeanParser(file, content, config); gen = parser.parse(); } ca...
java
private void writeClassDescriptions(BeanReferences references) throws IOException { // write out ref count first, which is the number of instances that are referenced output.writeInt(references.getReferences().size()); // write map of class name to a list of metatype names (which is empty if no...
java
public static <R> StandaloneMetaProperty<R> of(String propertyName, MetaBean metaBean, Class<R> clazz) { return new StandaloneMetaProperty<>(propertyName, metaBean, clazz, clazz); }
java
public byte[] write(Bean bean, boolean rootType) { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); try { write(bean, rootType, baos); } catch (IOException ex) { throw new IllegalStateException(ex); } return baos.toByteArray(); }
java
protected void propertySet(Bean bean, String propertyName, Object value, boolean quiet) { // used to enable 100% test coverage in beans if (quiet) { return; } throw new NoSuchElementException("Unknown property: " + propertyName); }
java
private void findChildBeans(Object obj, MetaProperty<?> mp, Class<?> beanClass, Deque<Bean> temp) { if (obj != null) { if (obj instanceof Bean) { temp.addFirst((Bean) obj); } else { SerIterator it = SerIteratorFactory.INSTANCE.create(obj, mp, beanClass); ...
java
private void findReferences(ImmutableBean root) { // handle root bean classes.put(root.getClass(), classInfoFromMetaBean(root.metaBean(), root.getClass())); classSerializationCount.put(root.getClass(), 1); // recursively check object graph Map<Object, Integer> objects = new Link...
java