java - .toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])? - Stack Overflow



java - .toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])? - Stack Overflow

From JetBrains Intellij Idea inspection:

There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).

In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.

This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).


Read full article from java - .toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])? - Stack Overflow


Language Guide (proto3)  |  Protocol Buffers  |  Google Developers



Language Guide (proto3)  |  Protocol Buffers  |  Google Developers

This guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to generate data access classes from your .proto files. It covers the proto3 version of the protocol buffers language: for information on the older proto2 syntax, see the Proto2 Language Guide.

This is a reference guide – for a step by step example that uses many of the features described in this document, see the tutorial for your chosen language (currently proto2 only; more proto3 documentation is coming soon).


Read full article from Language Guide (proto3)  |  Protocol Buffers  |  Google Developers


Missing value/null support for scalar value types in proto 3 · Issue #1606 · protocolbuffers/protobuf · GitHub



Missing value/null support for scalar value types in proto 3 · Issue #1606 · protocolbuffers/protobuf · GitHub

From the protobuf wire format we can tell whether a specific field exists or not. And in protobuf 2 generated code, all fields have a "HasXXX" method to tell whether the field exists or not in code. However in proto 3, we lost that ability. E.g. now we can't tell if a int32 field is missing, or has a value of 0 (default for int32 type).

In many scenario, we need the ability to differentiate missing vs default value (basically nullable support for scalar types).

Feng suggest workarounds:

  1. Use a wrapper message, such as google.protobuf.Int32Value. In proto3, message fields still have has-bits.
  2. Use an oneof. For example:
    message Test1 {
    oneof a_oneof {
    int32 a = 1;
    }
    }
    then you can check test.getAOneofCase().

However, this requires change the message definition, which is a no go if you need to keep the message compatible while upgrade from proto2 to proto 3.


Read full article from Missing value/null support for scalar value types in proto 3 · Issue #1606 · protocolbuffers/protobuf · GitHub


[Java] Generate hasXXX() methods for fields inside a oneof · Issue #2984 · protocolbuffers/protobuf · GitHub



[Java] Generate hasXXX() methods for fields inside a oneof · Issue #2984 · protocolbuffers/protobuf · GitHub

Currently in Java, one must compare the value of the oneof enum to know which field is contain in a oneof.
This is not very friendly to the end-user especially when you want to use oneof to provide nullability of the field. A generated hasXXX() method would be much more handy.
Also, I use mapstruct to map the generated protobuf classes to internal POJOs and it is capable of detecting if there is a hasFoo() method for a given foo field and using it in the mapping code it generates (see http://mapstruct.org/documentation/stable/reference/html/#source-presence-check). So such an enhancement would allow me to remove a lot of boilerplate code.


Read full article from [Java] Generate hasXXX() methods for fields inside a oneof · Issue #2984 · protocolbuffers/protobuf · GitHub


Standard Methods  |  Cloud APIs  |  Google Cloud



Standard Methods  |  Cloud APIs  |  Google Cloud

This chapter defines the concept of standard methods, which are List, Get, Create, Update, and Delete. Standard methods reduce complexity and increase consistency. Over 70% of API methods in the Google APIs repository are standard methods, which makes them much easier to learn and use.


Read full article from Standard Methods  |  Cloud APIs  |  Google Cloud


11 Rules of Writing – Common Mistakes [& Fixes]



11 Rules of Writing – Common Mistakes [& Fixes]

Getting your message across may seem a bit harder online than in real life. Not that there's less means to do so. A whole lot of methods including audio tracks, videos, animations and other visuals are available for you at any second.


Read full article from 11 Rules of Writing – Common Mistakes [& Fixes]


How to solve HTTP/1.1 411 Length Required error ? · Issue #713 · jakubroztocil/httpie · GitHub



How to solve HTTP/1.1 411 Length Required error ? · Issue #713 · jakubroztocil/httpie · GitHub

@bowbth it seems like the API is badly implemented. The 411 Length Required response status code would indicate that the Content-Length header wasn't defined in your request. However, httpie (as well as curl) correctly sends Content-Length: 0 (zero-length content).


Read full article from How to solve HTTP/1.1 411 Length Required error ? · Issue #713 · jakubroztocil/httpie · GitHub


How to solve HTTP/1.1 411 Length Required error ? · Issue #713 · jakubroztocil/httpie · GitHub



How to solve HTTP/1.1 411 Length Required error ? · Issue #713 · jakubroztocil/httpie · GitHub

@bowbth it seems like the API is badly implemented. The 411 Length Required response status code would indicate that the Content-Length header wasn't defined in your request. However, httpie (as well as curl) correctly sends Content-Length: 0 (zero-length content).


Read full article from How to solve HTTP/1.1 411 Length Required error ? · Issue #713 · jakubroztocil/httpie · GitHub


CodeMirror



CodeMirror

CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code, and comes with a number of language modes and addons that implement more advanced editing functionality.


Read full article from CodeMirror


RESTful API Design. Best Practices in a Nutshell.



RESTful API Design. Best Practices in a Nutshell.

Designing HTTP and RESTful APIs can be tricky as there is no official and enforced standard. Basically, there are many ways of implementing an API but some of them have proven in practice and are widley adopted. This post covers best practices for building HTTP and RESTful APIs. We'll talk about URL structure, HTTP methods, creating and updating resources, designing relationships, payload formats, pagination, versioning and many more.


Read full article from RESTful API Design. Best Practices in a Nutshell.


AssistedInject · google/guice Wiki · GitHub



AssistedInject · google/guice Wiki · GitHub

Factories are a well established pattern for creating value objects, model/domain objects (entities), or objects that combine parameterization and dependencies. Factories can be brittle and contain a lot of boilerplate. Guice can eliminate a lot of that boilerplate by auto-generating Factory implementations from simple interfaces. This process is (possibly misleadingly) known as assisted injection.


Read full article from AssistedInject · google/guice Wiki · GitHub


FactoryModuleBuilder (Guice latest API)



FactoryModuleBuilder (Guice latest API)

public final class FactoryModuleBuilder  extends java.lang.Object
Provides a factory that combines the caller's arguments with injector-supplied values to construct objects.

Defining a factory

Create an interface whose methods return the constructed type, or any of its supertypes. The method's parameters are the arguments required to build the constructed type.
public interface PaymentFactory {     Payment create(Date startDate, Money amount);   }
You can name your factory methods whatever you like, such as create, createPayment or newPayment.

Creating a type that accepts factory parameters

constructedType is a concrete class with an @Inject-annotated constructor. In addition to injector-supplied parameters, the constructor should have parameters that match each of the factory method's parameters. Each factory-supplied parameter requires an @Assisted annotation. This serves to document that the parameter is not bound by your application's modules.
public class RealPayment implements Payment {      @Inject     public RealPayment(        CreditService creditService,        AuthService authService,         @Assisted Date startDate,         @Assisted Money amount) {       ...     }   }

Multiple factory methods for the same type

If the factory contains many methods that return the same type, you can create multiple constructors in your concrete class, each constructor marked with with @AssistedInject, in order to match the different parameters types of the factory methods.
public interface PaymentFactory {      Payment create(Date startDate, Money amount);      Payment createWithoutDate(Money amount);   }     public class RealPayment implements Payment {     @AssistedInject     public RealPayment(        CreditService creditService,        AuthService authService,        @Assisted Date startDate,        @Assisted Money amount) {       ...     }       @AssistedInject     public RealPayment(        CreditService creditService,        AuthService authService,        @Assisted Money amount) {       ...     }   }


Read full article from FactoryModuleBuilder (Guice latest API)


How to Add a Device to Google Play Store - wikiHow



How to Add a Device to Google Play Store - wikiHow

When you add a device to Google Play, you can access your previous app, movie, music, book and other purchases on the new device. You can quickly add Android devices by signing in with the same Google account. If you have an Amazon Fire tablet, you can use some workarounds to load the Play Store and access all Android apps. It is not possible to add iOS (iPhone, iPad) or Windows devices to Google Play.


Read full article from How to Add a Device to Google Play Store - wikiHow


IDEA is constantly freezing – IDEs Support (IntelliJ Platform) | JetBrains



IDEA is constantly freezing – IDEs Support (IntelliJ Platform) | JetBrains

Do you have a lot of files in VCS Changes view? Try to minimize it by ignoring files or adding unversioned files to VCS and committing the modified files.


Read full article from IDEA is constantly freezing – IDEs Support (IntelliJ Platform) | JetBrains


Input freezes after MacOS key-selector on Mojave : JBR-998



Input freezes after MacOS key-selector on Mojave : JBR-998

Changing the language From English to SomeOtherLanguage, and then switching back to English fixes the issue, and lets you use the keyboard again


Read full article from Input freezes after MacOS key-selector on Mojave : JBR-998


collections - Is there a common Java utility to break a list into batches? - Stack Overflow



collections - Is there a common Java utility to break a list into batches? - Stack Overflow

Check out Lists.partition(java.util.List, int) from Google Guava:

Returns consecutive sublists of a list, each of the same size (the final list may be smaller). For example, partitioning a list containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer list containing two inner lists of three and two elements, all in the original order.


Read full article from collections - Is there a common Java utility to break a list into batches? - Stack Overflow


Find files in Google Drive - Computer - Google Drive Help



Find files in Google Drive - Computer - Google Drive Help

You can refine a search in Drive with these advanced searches. 

Note: Not all examples work on all devices.

Quotes

  • Find documents that contain an exact word or phrase.
  • Example: "match this phrase exactly"

Minus sign

  • Find documents that exclude a particular word. If you want "salsa," but not "dancing"...
  • Example: salsa -dancing

owner:

  • Find documents owned or shared by a specific person.
  • Examples:
    • owner:bob@gmail.com
    • from:bob@gmail.com

creator:

  • Find documents in a Team Drive created by a specific person
    • Example: creator:jane@yourdomain.com

Read full article from Find files in Google Drive - Computer - Google Drive Help


Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts