code
stringlengths
146
466k
prompt
stringlengths
54
1.5k
Of course, here is the Java code you requested: ```java @Override public void getActivityByUser(SocializeSession session, long id, ActionListener listener) { String userId = String.valueOf(id); String endpoint = getEndpoint(userId); listAsync(session, endpoint, listener); } ``` Hope this helps!
Create a Java method that does the following: "Get activity by id asynchronously.".
Of course, here is the Java code you requested: ```java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Define/obtain your entity Entity entity = Entity.newInstance("http://getsocialize.com", "Socialize"); // Get a reference to the button you want to trans...
Create a Java method that does the following: "Override to create the like button".
Of course, here is the Java code you requested: ```java public static <T extends Map.Entry<String, String>> String formEncode(Collection<T> parameters) throws IOException { ByteArrayOutputStream b = new ByteArrayOutputStream(); formEncode(parameters, b); return new String(b.toByteAr...
Create a Java method that does the following: "Form encode a collection of parameters into a string.".
Of course, here is the Java code you requested: ```java public static HttpParameters decodeForm(String form) { HttpParameters params = new HttpParameters(); if (isEmpty(form)) { return params; } for (String nvp : form.split("\\&")) { int equals = nvp.indexOf('=')...
Create a Java method that does the following: "Decode form string to HttpParameters object".
Of course, here is the Java code you requested: ```java public static <T extends Map.Entry<String, String>> Map<String, String> toMap(Collection<T> from) { HashMap<String, String> map = new HashMap<String, String>(); if (from != null) { for (Map.Entry<String, String> entry : from) { ...
Create a Java method that does the following: "Convert a Collection of Map. Entry to Map. Entry".
Of course, here is the Java code you requested: ```java public static <T extends Iterable<?>> T checkContentsNotNull(T iterable) { if (containsOrIsNull(iterable)) { throw new NullPointerException(); } return iterable; } ``` Hope this helps!
Create a Java method that does the following: "Check if the iterable is not null.".
Of course, here is the Java code you requested: ```java public static <T extends Iterable<?>> T checkContentsNotNull( T iterable, Object errorMessage) { if (containsOrIsNull(iterable)) { throw new NullPointerException(String.valueOf(errorMessage)); } return iterable; } ``` Hope this helps!
Create a Java method that does the following: "Check if the iterable is not null.".
Of course, here is the Java code you requested: ```java public static void checkElementIndex(int index, int size, String desc) { checkArgument(size >= 0, "negative size: %s", size); if (index < 0) { throw new IndexOutOfBoundsException( format("%s (%s) must not be negative", desc, index)); }...
Create a Java method that does the following: "Check that the index is valid for a CID element.".
Of course, here is the Java code you requested: ```java public static void checkPositionIndex(int index, int size, String desc) { checkArgument(size >= 0, "negative size: %s", size); if (index < 0) { throw new IndexOutOfBoundsException(format( "%s (%s) must not be negative", desc, index)); ...
Create a Java method that does the following: "Check the position index.".
Of course, here is the Java code you requested: ```java public static void checkPositionIndexes(int start, int end, int size) { checkPositionIndex(start, size, "start index"); checkPositionIndex(end, size, "end index"); if (end < start) { throw new IndexOutOfBoundsException(format( "end ind...
Create a Java method that does the following: "Check that the start and end index are valid.".
Of course, here is the Java code you requested: ```java @Override protected void postToJSON(Subscription from, JSONObject to) throws JSONException { try { Entity entityObject = from.getEntity(); User userObject = from.getUser(); Long date = from.getDate(); if(entityObject != null) { if(!StringU...
Create a Java method that does the following: "Post to JSON.".
Of course, here is the Java code you requested: ```java public boolean put(K strKey, E object, long ttl) { return put(strKey, object, ttl, false); } ``` Hope this helps!
Create a Java method that does the following: "Associates the specified object with the specified key in this map.".
Of course, here is the Java code you requested: ```java public boolean put(K strKey, E object, boolean eternal) { return put(strKey, object, defaultTTL, eternal); } ``` Hope this helps!
Create a Java method that does the following: "Associates the specified object with the specified key in this cache.".
Of course, here is the Java code you requested: ```java protected synchronized boolean put(K k, E object, long ttl, boolean eternal) { // Check the key map first if(exists(k)) { TTLObject<K, E> ttlObject = getTTLObject(k); Key<K> key = keys.get(k); key.setTime(System.currentTimeMillis()); ...
Create a Java method that does the following: "Updates the data in the object with the specified key.".
Of course, here is the Java code you requested: ```java public synchronized E get(K key) { TTLObject<K, E> obj = getTTLObject(key); if(obj != null && !isExpired(obj)) { if(extendOnGet) { extendTTL(key); } if(eventListener != null) { eventListener.onGet(obj.getObject()); } ...
Create a Java method that does the following: "Gets the object with the specified key from the cache. If the object is not yet present in the cache it will be created and returned.".
Of course, here is the Java code you requested: ```java public Collection<E> values() { Collection<E> values = null; Collection<TTLObject<K, E>> ttls = objects.values(); if(ttls != null) { values = new ArrayList<E>(ttls.size()); for (TTLObject<K, E> t : ttls) { if(!isExpired(t)) { values.ad...
Create a Java method that does the following: "Returns a collection of all the values of this object.".
Of course, here is the Java code you requested: ```java public boolean exists(K k) { Key<K> key = keys.get(k); if(key != null) { return objects.get(key) != null; } return false; } ``` Hope this helps!
Create a Java method that does the following: "Checks if the object with the given key exists.".
Of course, here is the Java code you requested: ```java public void loadImageByUrl(final String url, int width, int height, final ImageLoadListener listener) { ImageLoadRequest request = makeRequest(); request.setUrl(url); request.setType(ImageLoadType.URL); request.setScaleWidth(width); request.setScaleHeig...
Create a Java method that does the following: "Load an image from a URL.".
Of course, here is the Java code you requested: ```java @Override public void addLike(SocializeSession session, Entity entity, LikeOptions shareOptions, LikeListener listener, SocialNetwork... networks) { Like c = new Like(); c.setEntitySafe(entity); setPropagationData(c, shareOptions, networks); setLocati...
Create a Java method that does the following: "Add a like to an entity.".
Of course, here is the Java code you requested: ```java @Override public void getLikesByApplication(SocializeSession session, int startIndex, int endIndex, LikeListener listener) { listAsync(session, ENDPOINT, null, null, null, startIndex, endIndex, listener); } ``` Hope this helps!
Create a Java method that does the following: "Get likes by application.".
Of course, here is the Java code you requested: ```java public long getTotalLength() { long contentLen = 0; for (FormBodyPart part : this.parts) { ContentBody body = part.getBody(); long len = body.getContentLength(); if (len >= 0) { contentLen += len; } else { return -1; } }...
Create a Java method that does the following: "Returns the total length of this form body.".
Of course, here is the Java code you requested: ```java @Override public void addView(SocializeSession session, Entity entity, Location location, ViewListener listener) { View c = new View(); c.setEntitySafe(entity); setLocation(c); List<View> list = new ArrayList<View>(1); list.add(c); postAsync...
Create a Java method that does the following: "Add a view to the view list.".
Of course, here is the Java code you requested: ```java @Override public void send(Set<OpenTsdbMetric> metrics) { if (metrics.isEmpty()) return; Writer writer = null; try { writer = this.writerFactory.getWriter(); write(metrics, writer); } catch (Exception e) { if (logger.isDebugEnabled()) { ...
Create a Java method that does the following: "Send a set of OpenTsdbMetrics to the codahale server.".
Of course, here is the Java code you requested: ```java public void send(Set<OpenTsdbMetric> metrics) { // we set the patch size because of existing issue in opentsdb where large batch of metrics failed // see at https://groups.google.com/forum/#!topic/opentsdb/U-0ak_v8qu0 // we recommend batch...
Create a Java method that does the following: "Send a set of OpenTsdbMetrics to the server.".
Of course, here is the Java code you requested: ```java public static String encodeTagsInName(final String name, final String tags) throws IllegalArgumentException { return encodeTagsInName(name, parseTags(tags)); } ``` Hope this helps!
Create a Java method that does the following: "Encode tags in name.".
Of course, here is the Java code you requested: ```java public static String encodeTagsInName(final String name, final Map<String, String> tags) { return String.format("TAG(%s)%s", formatTags(tags), sanitize(name)); } ``` Hope this helps!
Create a Java method that does the following: "Encode tags in name.".
Of course, here is the Java code you requested: ```java public String toTelnetPutString() { String tagString = formatTags(tags); return String.format("put %s %d %s %s%n", metric, timestamp, value, tagString); } ``` Hope this helps!
Create a Java method that does the following: "Returns a string representation of this object.".
Of course, here is the Java code you requested: ```java @Override public String toHumanString() { if (unicode) { return domain; } final IDNA.Info idnaInfo = new IDNA.Info(); final StringBuilder idnaOutput = new StringBuilder(); IDNA.getUTS46Instance(IDNA.DEFAULT)...
Create a Java method that does the following: "Returns a human - readable string representation of the domain.".
Of course, here is the Java code you requested: ```java public static String encode(final String input, final Charset charset) { return encode(parse(input), charset); } ``` Hope this helps!
Create a Java method that does the following: "Encode a string using the specified charset.".
Of course, here is the Java code you requested: ```java public static String encode(final List<NameValue> input, final Charset charset) { if (input == null) { throw new NullPointerException("input"); } if (charset == null) { throw new NullPointerException("charset"); ...
Create a Java method that does the following: "Encode a list of NameValue objects using the specified charset.".
Of course, here is the Java code you requested: ```java public InetAddress toInetAddress() { final byte[] bytes = new byte[16]; for (int i = 0; i < pieces.length; i++) { bytes[i*2] = (byte)((pieces[i] >> 8) & 0xFF); bytes[i*2+1] = (byte)(pieces[i] & 0xFF); } try...
Create a Java method that does the following: "Returns the InetAddress object of the record.".
Of course, here is the Java code you requested: ```java public static IPv6Address fromInet6Address(final Inet6Address inet6Address) { final byte[] bytes = inet6Address.getAddress(); final short[] pieces = new short[8]; for (int i = 0; i < pieces.length; i++) { pieces[i] = (short) ((...
Create a Java method that does the following: "Create an IPv6 address from an Inet6Address object.".
Of course, here is the Java code you requested: ```java public String queryParameter(final String name) { if (name == null) { throw new NullPointerException("name is null"); } if (query == null || query.isEmpty()) { return null; } int start = 0; d...
Create a Java method that does the following: "Query parameter.".
Of course, here is the Java code you requested: ```java public List<String> queryParameters(final String name) { if (name == null) { throw new NullPointerException("name is null"); } if (query == null || query.isEmpty()) { return null; } int start = 0; ...
Create a Java method that does the following: "Get the query parameters.".
Of course, here is the Java code you requested: ```java public static URL fromJavaURI(java.net.URI uri) { //TODO: Let's do this more efficient. try { return new URLParser(uri.toString()).parse(); } catch (GalimatiasParseException e) { // This should not happen. ...
Create a Java method that does the following: "Returns a URL from a Java URI.".
Of course, here is the Java code you requested: ```java public <T, U> U forStream( String fileName, Class<T> clazz, Map<String, Object> params, Function<? super Stream<T>, U> handleStream) { String sql = getTemplate(fileName, params); SqlParameterSource s...
Create a Java method that does the following: "Query for a stream of a single class.".
Of course, here is the Java code you requested: ```java public <U> U forStream( String fileName, Map<String, Object> params, Function<? super Stream<Map<String, Object>>, U> handleStream) { String sql = getTemplate(fileName, params); SqlParameterSource sps = paramBui...
Create a Java method that does the following: "Query a stream of a record set.".
Of course, here is the Java code you requested: ```java private <T, U> U queryStreamWithOrdinalParams( String sql, PreparedStatementSetter pss, RowMapper<T> mapper, Function<? super Stream<T>, U> handleStream) { SQLExceptionTranslator excTranslator = jdbcTemplate...
Create a Java method that does the following: "Query a stream with ordinal parameters.".
Of course, here is the Java code you requested: ```java private <T, U> U queryStreamWithNamedParams( String sql, SqlParameterSource sps, RowMapper<T> mapper, Function<? super Stream<T>, U> handleStream) { SQLExceptionTranslator excTranslator = jdbcTemplate.getExc...
Create a Java method that does the following: "Query Stream with named params.".
Of course, here is the Java code you requested: ```java public static Field[] get(Class<?> clazz) { Field[] fields = CACHED_FIELDS.get(clazz); if (fields == null) { fields = clazz.getFields(); CACHED_FIELDS.putIfAbsent(clazz, fields); } return fields; } ``` ...
Create a Java method that does the following: "Gets the fields of a class.".
Of course, here is the Java code you requested: ```java @Override public Object getValue(String paramName) { Object value = values.get(paramName); if (value == null) { return null; } return Jsr310JdbcUtils.convertIfNecessary(value, zoneId); } ``` Hope this helps!
Create a Java method that does the following: "Gets the value of the parameter.".
Of course, here is the Java code you requested: ```java private Optional<T> fetchRow() { if (this.row != null) { // already fetched return Optional.of(this.row); } this.hasReachedEos = hasReachedEos || ! wrapSqlException(() -> rs.next()); if (this.hasReachedEos)...
Create a Java method that does the following: "Fetch the next row from the result set.".
Of course, here is the Java code you requested: ```java protected static ZonedDateTime getAsZonedDateTime(ResultSet rs, int index, ZoneId zoneId) throws SQLException { Timestamp timestamp = rs.getTimestamp(index); if (timestamp != null) { return timestamp.toLocalDateTime().atZone(zoneId)...
Create a Java method that does the following: "Gets a Timestamp in the ResultSet as a ZonedDateTime.".
Of course, here is the Java code you requested: ```java protected static OffsetDateTime getAsOffsetDateTime(ResultSet rs, int index, ZoneId zoneId) throws SQLException { Timestamp timestamp = rs.getTimestamp(index); if (timestamp != null) { return timestamp.toLocalDateTime().atZone(zoneI...
Create a Java method that does the following: "Gets a Timestamp in the given index as an OffsetDateTime.".
Of course, here is the Java code you requested: ```java @Override public boolean hasValue(String paramName) { return privateFields.contains(paramName) || publicFeilds.containsKey(paramName); } ``` Hope this helps!
Create a Java method that does the following: "Check if a value is present in the class.".
Of course, here is the Java code you requested: ```java private String underscoreName(String name) { if (!StringUtils.hasLength(name)) { return ""; } StringBuilder result = new StringBuilder(); result.append(name.substring(0, 1) .toLowerCase()); for (...
Create a Java method that does the following: "underscoreName This method returns the name of the class.".
Of course, here is the Java code you requested: ```java protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException { super.doSetValue(ps, parameterPosition, Jsr310JdbcUtils.convertIfNecessary(argValue, zoneId)); } ``` Hope this helps!
Create a Java method that does the following: "Override to set the value in the statement.".
Of course, here is the Java code you requested: ```java public File upload(int pollingInterval) throws UploadFailureException { RequestHelper requestHelper = client.getRequestHelper(); URI uploadUrl = Urls.uploadFromUrl(sourceUrl, client.getPublicKey(),store); String token = requestHelper.execu...
Create a Java method that does the following: "Upload a file from the sourceUrl using pollingInterval seconds".
Of course, here is the Java code you requested: ```java public CdnPathBuilder crop(int width, int height) { dimensionsGuard(width, height); sb.append("/-/crop/") .append(width) .append("x") .append(height); return this; } ``` Hope this helps!
Create a Java method that does the following: "Crop the image to the specified width and height.".
Of course, here is the Java code you requested: ```java public CdnPathBuilder cropCenter(int width, int height) { dimensionsGuard(width, height); sb.append("/-/crop/") .append(width) .append("x") .append(height) .append("/center"); ...
Create a Java method that does the following: "Crop center.".
Of course, here is the Java code you requested: ```java public CdnPathBuilder cropColor(int width, int height, Color color) { dimensionsGuard(width, height); sb.append("/-/crop/") .append(width) .append("x") .append(height) .append("/") ...
Create a Java method that does the following: "Crop the image to the specified size and color.".
Of course, here is the Java code you requested: ```java public CdnPathBuilder resizeWidth(int width) { dimensionGuard(width); sb.append("/-/resize/") .append(width) .append("x"); return this; } ``` Hope this helps!
Create a Java method that does the following: "Resize the image to the specified width.".
Of course, here is the Java code you requested: ```java public CdnPathBuilder resize(int width, int height) { dimensionsGuard(width, height); sb.append("/-/resize/") .append(width) .append("x") .append(height); return this; } ``` Hope this he...
Create a Java method that does the following: "Resize the path.".
Of course, here is the Java code you requested: ```java public CdnPathBuilder scaleCrop(int width, int height) { dimensionsGuard(width, height); sb.append("/-/scale_crop/") .append(width) .append("x") .append(height); return this; } ``` Hope ...
Create a Java method that does the following: "Scale the image to fit into the image.".
Of course, here is the Java code you requested: ```java public CdnPathBuilder sharp(int strength) { if (strength < 0 || strength > 20) { strength = 5; } sb.append("/-/sharp/") .append(strength); return this; } ``` Hope this helps!
Create a Java method that does the following: "Add a sharp path.".
Of course, here is the Java code you requested: ```java public void saveFile(String fileId) { URI url = Urls.apiFileStorage(fileId); RequestHelper requestHelper = getRequestHelper(); requestHelper.executeCommand(new HttpPost(url), true); } ``` Hope this helps!
Create a Java method that does the following: "Saves a file to the file system.".
Of course, here is the Java code you requested: ```java public File upload() throws UploadFailureException { URI uploadUrl = Urls.uploadBase(); HttpPost request = new HttpPost(uploadUrl); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); entityBuilder.addTextBody(...
Create a Java method that does the following: "Upload the CA file to the server.".
Of course, here is the Java code you requested: ```java public static URI uploadFromUrl(String sourceUrl, String pubKey, String store) { URIBuilder builder = new URIBuilder(URI.create(UPLOAD_BASE)); builder.setPath("/from_url/") .setParameter("source_url", sourceUrl) .se...
Create a Java method that does the following: "Create an upload URI from a source URL.".
Of course, here is the Java code you requested: ```java protected List<Object> getModules() { List<Object> result = new ArrayList<Object>(); result.add(new InjectingActivityModule(this, this)); return result; } ``` Hope this helps!
Create a Java method that does the following: "Get the modules to inject.".
Of course, here is the Java code you requested: ```java protected List<Object> getModules() { List<Object> result = new ArrayList<Object>(); result.add(new InjectingBroadcastReceiverModule(mContext, this, this)); return result; } ``` Hope this helps!
Create a Java method that does the following: "Returns the list of modules to inject.".
Of course, here is the Java code you requested: ```java @Override protected void onCreate(android.os.Bundle savedInstanceState) { // extend the application-scope object graph with the modules for this activity mObjectGraph = ((Injector) getApplication()).getObjectGraph().plus(getModules().toArray()...
Create a Java method that does the following: "Override onCreate to inject the CIDCTYPE".
Of course, here is the Java code you requested: ```java protected List<Object> getModules() { List<Object> result = new ArrayList<Object>(); result.add(new InjectingFragmentModule(this, this)); return result; } ``` Hope this helps!
Create a Java method that does the following: "Get the modules to inject.".
Of course, here is the Java code you requested: ```java protected List<Object> getModules() { List<Object> result = new ArrayList<Object>(); result.addAll(mSeedModules); result.add(new InjectingApplicationModule(this, this)); return result; } ``` Hope this helps!
Create a Java method that does the following: "Get the modules.".
Of course, here is the Java code you requested: ```java @Override public void onReceive(Context context, Intent intent) { mContext = context; // extend the application-scope object graph with the modules for this AppWidgetProvider mObjectGraph = ((Injector) context.getApplicationContext())...
Create a Java method that does the following: "Override this method to inject our AppWidgetProvider s AppWidgetNamespace object graph with the modules for this AppWidgetProvider".
Of course, here is the Java code you requested: ```java protected List<Object> getModules() { List<Object> result = new ArrayList<Object>(); result.add(new InjectingAppWidgetProviderModule(mContext, this, this)); return result; } ``` Hope this helps!
Create a Java method that does the following: "Get the modules to inject.".
Of course, here is the Java code you requested: ```java private void onSpecialClick() { AlertDialog alertDialog = AlertDialog.build(this) .setTitle("标题") .setMessage("提示信息") // Listener 写null,Button被点击时,Alertdialog就不会自动dismiss了。 .setNeutralButton(...
Create a Java method that does the following: "onSpecialClick This method is called when the user clicks on the special button button.".
Of course, here is the Java code you requested: ```java private void generateStoreNewProxyMatcher(final CodeBlock block) { block.newobj(CodegenUtils.p(ProxyMatcher.class)) .dup() .invokespecial(CodegenUtils.p(ProxyMatcher.class), "<init>", CodegenUtils.sig(void.class...
Create a Java method that does the following: "Generate store new proxy matcher.".
Of course, here is the Java code you requested: ```java @Nullable public Class<?> findClass(final String className) { Objects.requireNonNull(className); try { return (Class<?>) findClass.invoke(loader, className); } catch (IllegalAccessException | InvocationTargetException ...
Create a Java method that does the following: "Find class by name.".
Of course, here is the Java code you requested: ```java public Class<?> loadClass(final String className, final byte[] bytecode) { Objects.requireNonNull(className); Objects.requireNonNull(bytecode); try { return (Class<?>) loadClass.invoke(loader, className, bytecode, 0, ...
Create a Java method that does the following: "Load a class from the class loader.".
Of course, here is the Java code you requested: ```java private static void runMethodTransformers(final ParserClassNode classNode) throws Exception { // TODO: comment above may be right, but it's still dangerous // iterate through all rule methods // since the ruleMethods map on the...
Create a Java method that does the following: "Run all method transforms on the class node.".
Of course, here is the Java code you requested: ```java public boolean append(final char c) { if (get() == null) return set(new StringBuilder().append(c)); get().append(c); return true; } ``` Hope this helps!
Create a Java method that does the following: "Append a char to the base64 string.".
Of course, here is the Java code you requested: ```java public static Class<?> getClassForType(final Type type) { Objects.requireNonNull(type, "type"); switch (type.getSort()) { case Type.BOOLEAN: return boolean.class; case Type.BYTE: return b...
Create a Java method that does the following: "Gets the Class for the type.".
Of course, here is the Java code you requested: ```java public static boolean isAssignableTo(final String classInternalName, final Class<?> type) { Objects.requireNonNull(classInternalName, "classInternalName"); Objects.requireNonNull(type, "type"); final Class<?> c = CACHE.loadCla...
Create a Java method that does the following: "Check if a class is assignable to another class.".
Of course, here is the Java code you requested: ```java private void copyParseInfo(final FileSystem zipfs) throws IOException { final Path path = zipfs.getPath(INFO_PATH); try ( final BufferedWriter writer = Files.newBufferedWriter(path, UTF_8); ) { sb.setLe...
Create a Java method that does the following: "Copy parse info to a file.".
Of course, here is the Java code you requested: ```java public static void hash(@Nonnull final InstructionGroup group, @Nonnull final String className) { final InstructionGroupHasher groupHasher = new InstructionGroupHasher(group, className); final String name = groupHasher.hash...
Create a Java method that does the following: "Hash a class name and instruction group.".
Of course, here is the Java code you requested: ```java @DontLabel public Rule anyOf(final String characters) { Objects.requireNonNull(characters); // TODO: see in this Characters class whether it is possible to wrap return anyOf(characters.toCharArray()); } ``` Hope this helps!
Create a Java method that does the following: "Create a Rule that evaluates to a Sequence of characters that is contained in the base64 encoded string.".
Of course, here is the Java code you requested: ```java @Cached @DontLabel public Rule anyOf(final Characters characters) { Objects.requireNonNull(characters); if (!characters.isSubtractive() && characters.getChars().length == 1) return ch(characters.getChars()[0]); if (...
Create a Java method that does the following: "Gets the rule that matches any of the given characters.".
Of course, here is the Java code you requested: ```java @DontLabel public Rule noneOf(final String characters) { Objects.requireNonNull(characters); return noneOf(characters.toCharArray()); } ``` Hope this helps!
Create a Java method that does the following: "Create a Rule that accepts all characters in the sequence of characters.".
Of course, here is the Java code you requested: ```java @Cached @DontLabel public Rule string(final char... characters) { if (characters.length == 1) return ch(characters[0]); // optimize one-char strings return new StringMatcher(new String(characters)); } ``` Hope this hel...
Create a Java method that does the following: "A rule that matches a sequence of characters.".
Of course, here is the Java code you requested: ```java public Rule longestStringIgnoreCase(final String first, final String second, final String... others) { return trieIgnoreCase(first, second, others); } ``` Hope this helps!
Create a Java method that does the following: "Returns a rule that accepts the longest string of two words ignoring case.".
Of course, here is the Java code you requested: ```java @Cached public Rule trieIgnoreCase(final Collection<String> strings) { final List<String> list = ImmutableList.copyOf(strings); final TrieBuilder builder = Trie.newBuilder(); list.forEach(builder::addWord); return new Ca...
Create a Java method that does the following: "Create a CaseInsensitiveTrieMatcher from a collection of strings.".
Of course, here is the Java code you requested: ```java @DontLabel public Rule firstOf(final Object rule, final Object rule2, final Object... moreRules) { Objects.requireNonNull(moreRules); final Object[] rules = ImmutableList.builder().add(rule).add(rule2) .add(moreRules).b...
Create a Java method that does the following: "Gets the first rule of a sequence of two CRA rules.".
Of course, here is the Java code you requested: ```java @Cached @DontLabel public Rule optional(final Object rule) { Objects.requireNonNull(rule); return new OptionalMatcher(toRule(rule)); } ``` Hope this helps!
Create a Java method that does the following: "Returns a Rule that matches the specified rule.".
Of course, here is the Java code you requested: ```java @DontLabel public final JoinMatcherBootstrap<V, BaseParser<V>> join(final Object rule) { final Rule matcher = toRule(rule); return new JoinMatcherBootstrap<>(this, matcher); } ``` Hope this helps!
Create a Java method that does the following: "Create a new JoinMatcherBootstrap for the given rule.".
Of course, here is the Java code you requested: ```java @DontLabel public final RepeatMatcherBuilder<V> repeat(final Object rule, final Object rule2, final Object... moreRules) { Objects.requireNonNull(moreRules); return repeat(sequence(rule, rule2, moreRules)); } ``` Hope this hel...
Create a Java method that does the following: "Create a repeat matcher builder.".
Of course, here is the Java code you requested: ```java @DontExtend protected Rule fromStringLiteral(final String string) { Objects.requireNonNull(string); return fromCharArray(string.toCharArray()); } ``` Hope this helps!
Create a Java method that does the following: "Create a Rule from a string literal.".
Of course, here is the Java code you requested: ```java @DontExtend public Rule[] toRules(final Object... objects) { return Arrays.stream(objects).map(this::toRule).toArray(Rule[]::new); } ``` Hope this helps!
Create a Java method that does the following: "Converts an array of objects to a list of rules.".
Of course, here is the Java code you requested: ```java @DontExtend public Rule toRule(final Object obj) { Objects.requireNonNull(obj); if (obj instanceof Rule) return (Rule) obj; if (obj instanceof Character) return fromCharLiteral((Character) obj); if (...
Create a Java method that does the following: "Converts an object to a rule.".
Of course, here is the Java code you requested: ```java public <E extends V> E peekAs(final Class<E> c) { return c.cast(peek()); } ``` Hope this helps!
Create a Java method that does the following: "Peek as a class.".
Of course, here is the Java code you requested: ```java @Override public <T> boolean match(final MatcherContext<T> context) { final Matcher matcher = context.getMatcher(); final PreMatchEvent<T> preMatchEvent = new PreMatchEvent<>(context); bus.post(preMatchEvent); if (throwab...
Create a Java method that does the following: "Match a single phrase.".
Of course, here is the Java code you requested: ```java public boolean overlapsWith(final IndexRange other) { Objects.requireNonNull(other, "other"); return end > other.start && other.end > start; } ``` Hope this helps!
Create a Java method that does the following: "Checks if this range overlaps with the other range.".
Of course, here is the Java code you requested: ```java public static <P extends BaseParser<V>, V> P createParser( @Nonnull final Class<P> parserClass, final Object... constructorArgs) { Objects.requireNonNull(parserClass, "parserClass"); try { final Class<?> extendedClass ...
Create a Java method that does the following: "Create a parser instance.".
Of course, here is the Java code you requested: ```java public static <P extends BaseParser<V>, V> byte[] getByteCode( final Class<P> parserClass) { try { return ParserTransformer.getByteCode(parserClass); } catch (Exception e) { throw new RuntimeException("failed to...
Create a Java method that does the following: "Gets the byte code for a single parser class.".
Of course, here is the Java code you requested: ```java public static Matcher unwrap(final Matcher matcher) { if (matcher instanceof ProxyMatcher) { final ProxyMatcher proxyMatcher = (ProxyMatcher) matcher; if (proxyMatcher.dirty) proxyMatcher.apply(); re...
Create a Java method that does the following: "Unwraps a Matcher.".
Of course, here is the Java code you requested: ```java @Override public <V> boolean match(final MatcherContext<V> context) { /* * Since the trie knows about the length of its possible longest match, * extract that many characters from the buffer. Remind that .extract() * wil...
Create a Java method that does the following: "Override the match method to perform the actual match.".
Of course, here is the Java code you requested: ```java public final boolean post(@Nonnull final Object object) { Objects.requireNonNull(object); bus.post(object); return true; } ``` Hope this helps!
Create a Java method that does the following: "Post an object to the CRA.".
Of course, here is the Java code you requested: ```java @Override public <V> MatcherContext<V> getSubContext(final MatcherContext<V> context) { return context.getSubContext(this); } ``` Hope this helps!
Create a Java method that does the following: "Get the sub context.".
Of course, here is the Java code you requested: ```java public Rule max(final int nrCycles) { Preconditions.checkArgument(nrCycles >= 0, "illegal repetition number specified (" + nrCycles + "), must be 0 or greater"); return range(Range.atMost(nrCycles)); } ``` Hope...
Create a Java method that does the following: "Returns the max rule.".
Of course, here is the Java code you requested: ```java public Rule times(final int minCycles, final int maxCycles) { Preconditions.checkArgument(minCycles >= 0, "illegal repetition number specified (" + minCycles + "), must be 0 or greater"); Preconditions.checkArgument...
Create a Java method that does the following: "Create a Rule that accepts a sequence of cycles.".
Of course, here is the Java code you requested: ```java @Cached @DontLabel public Rule range(final Range<Integer> range) { Objects.requireNonNull(range, "range must not be null"); final Range<Integer> realRange = normalizeRange(range); /* * We always have a lower bound ...
Create a Java method that does the following: "Returns a Rule that matches a range of tokens.".