Failed to add copy of type collection input. Collections in Java




configuration mime-types (6)

If anyone is encountering errors like Error: Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute and/or other scripts stop working when running this fix, it may help to remove it first by doing the following:

At least this solved my problem

I need to add a new MIME mapping for .woff file extensions for IIS Express.

If I add the following snippet to IIS Express's "applicationhost.config" it works fine:

...

But I would really like to add it to my "web.config" so that not every developer has to change their "applicationhost.config" locally.

So I removed it again from the "applicationhost.config" file and added the following snippet to the project's "web.config":

...

Unfortunately this doesn't seem to be the case because when I try to access the .woff file I get an HTTP 404.3 error.

What am I doing wrong?

Putting it in "web.config" is fine. The problem is that I was using the MIME type incorrectly. Instead of font/x-woff or font/x-font-woff it should be application/font-woff :

...

See also this answer regarding MIME type: https://.com/a/5142316/135441

Update 4/10/2013

I'm having a problem getting my ASP.NET 5.0/MVC 6 application to serve static binary file types or to view virtual directories. It looks like this is done in Configure() at startup. See http://docs.asp.net/en/latest/fundamentals/static-files.html for a quick primer.

To resolve the issue, double-click the "MIME Types" configuration option while the IIS root node is selected in the left pane and click the "Add..." link in the Actions pane on the right. The following dialog will appear. Add the .woff extension and specify "application/x-font-woff" as the corresponding MIME type:

Follow same for woff2 with app/x-font-woff2

I don't use IIS Express, but am developing against my local full IIS 7.

So if anyone else tries this I had to add the mime type for woff via IIS Manager

Algorithms + Data Structures = Programs.
Niklaus Wirth.


Introduction

When writing a program, very often there is a need to store a set of objects. These can be numbers, strings, objects of custom classes, etc. In this article I will try to classify and describe the main classes of collections in simple language.

Some readers may have a question: why do we need collections if we have arrays? In fact, many people use collections where they are needed and not needed. But there are situations when it is necessary, for example, to dynamically change the size of the data structure, or automatically arrange the data structure as elements are added, etc.

This article will focus specifically on Java Collections Framework, since there are numerous alternatives:
1. Guava(Google Collections Library) - The library adds several useful implementations of data structures such as multiset, multimap, and bidirectional mapping. Improved efficiency.
2. Trove library- Implementation of collections that allows you to store primitives (in the Java Collections Framework, primitives cannot be stored, only wrapper types), which allows for increased efficiency.
3. P.C.J.(Primitive Collections for Java) - like Trove, they are designed for primitive types, which will improve efficiency.
4. Finally, you can write your own collection (the same linked list). But this approach is not recommended :)

As you can see, there is plenty to choose from. But first, you need to master the basic Java collections that are used most often. And also some third-party libraries implement interfaces Java Collections Framework(Guava example). That is, knowledge of the class hierarchy of base collections will allow you to quickly master third-party libraries.


Basic Interfaces

There are two basic interfaces in the Java collections library, the implementations of which represent the totality of all collection classes:

1. Collection- a collection contains a set of objects (elements). The main methods for manipulating data are defined here, such as insertion (add, addAll), deletion ( remove, removeAll, clear), search ( contains)
2. Map- describes a collection consisting of key-value pairs. Each key has only one value, which corresponds to the mathematical concept of a single-valued function or mapping (tar). Such a collection is often called a dictionary or an associative array. It does NOT relate to the Collection interface in any way and is independent.

Although the framework is called Java Collections Framework, interface map and its implementation included to the framework too!
The Collection and Map interfaces are basic, but they are not the only ones. They are expanded by other interfaces that add additional functionality. We'll talk about them later.


Collection interface

Let's look at the main interfaces related to Collection:

As can be seen from the diagram, the interface Collection is not basic (what an intrigue: D). Interface Collection extends the interface Iterable, which has only one iterator() method. This means that any collection that is an heir Iterable should return an iterator.


Implementations of the Set interface

Let's look at the following diagram. We're trying to figure it out :)

HashSet- a collection that does not allow storing identical objects (like any Set). HashSet encapsulates an object HashMap(that is, it uses a hash table for storage).
As most readers probably know, a hash table stores information using something called a hashing mechanism, in which the contents of a key are used to determine a unique value called a hash code. This hash code is then used as an index to which the data accessible by that key is associated. Converting the key to a hash code is done automatically - you never see the hash code itself. Also your code can't directly index the hash table. The benefit of hashing is that it ensures constant execution time for the add(), contains(), remove() And size(), even for large sets.

If you want to use HashSet to store objects of YOUR classes, then you MUST override the hashCode() and equals() methods, otherwise two logically identical objects will be considered different, since when adding an element to the collection, the hashCode() method of the Object class will be called (which will most likely return a different hash code for your objects).
It is important to note that the HashSet class does not guarantee that the elements are in order, since the hashing process itself does not typically produce sorted sets. If you need sorted sets, then another collection type such as the TreeSet class may be a better choice.

LinkedHashSet- maintains a linked list of elements of a set in the order in which they were inserted. This allows for an orderly iteration of the insertion into the set. That is, when iterating over an object of the LinkedHashSet class using an iterator, the elements are retrieved in the order in which they were added.

TreeSet- a collection that stores its elements in the form of a tree ordered by values. A TreeSet encapsulates a TreeMap, which in turn uses a balanced binary red-black tree to store elements. The good thing about TreeSet is that the add, remove and contains operations require a guaranteed log(n) time.


Implementations of the Queue interface

Here I have given a very simplified hierarchy.

PriorityQueue- the only direct implementation of the interface Queue(not to mention LinkedList, which is more of a list than a queue).
This queue orders elements either by their natural order (using the interface Comparable), or using the interface Comparator, received in the constructor.


Implementations of the Map interface

Interface Map associates unique keys with values. A key is an object that you use to later retrieve data. By specifying a key and value, you can put values ​​into a map object. Once this value is stored, you can retrieve it by key. Interface Map is a generic interface declared as shown below.

interface Mar<К, V>

Here K indicates the type of keys and V the type of stored values.

The class hierarchy is very similar to the Set hierarchy:

LinkedHashMap- extends the class HashMap. It creates a linked list of elements in the map, arranged in the order in which they were inserted. This allows you to sort through the map in insertion order. That is, when iterating through the collection view of a LinkedHashMap object, the elements will be returned in the order in which they were inserted. You can also create a LinkedHashMap that returns its elements in the order in which they were last accessed.
I also recommend reading http://habrahabr.ru/post/129037/


Outdated collections

The following collections are obsolete and their use is discouraged but not prohibited.

1. Enumeration- analogue of the Iterator interface.

2. Vector- analogue of the ArrayList class; maintains an ordered list of elements stored in an "internal" array.

3. Stack- a class derived from Vector that adds methods for pushing and popping elements, so that a list can be interpreted in terms commonly used to describe a stack data structure.

4. Dictionary- an analogue of the Map interface, although it is an abstract class and not an interface.

5. Hashtable- analogue of HashMap.

All Hashtable, Stack, Vector methods are synchronized, which makes them less efficient in single-threaded applications.


Synced Collections

You can get synchronized collection objects using static methods synchronizedMap And synchronizedList class Collections.

Map m = Collections.synchronizedMap(new HashMap());
List l = Collections.synchronizedList(new ArrayList());

The synchronized collection wrappers synchronizedMap and synchronizedList are sometimes called conditionally thread-safe - all individual operations are thread-safe, but sequences of operations where the control thread depends on the results of previous operations can cause contention for data.
(source http://www.ibm.com/developerworks/ru/library/j-jtp07233/)
The conditional thread safety provided by synchronizedList and synchronizedMap poses a hidden threat - developers assume that because these collections are synchronized that they are completely thread safe, and neglect to properly synchronize composite operations. As a result, although these programs work under light load, under heavy load they can start throwing NullPointerException or ConcurrentModificationException.

In addition, there is always the possibility of "classical" synchronization using the synchronized block.


Putting it all together

So, let's look at the resulting class diagram:


Fig 7
Big picture: http://piccy.info/view3/4760074/fd5ec046ce4336b8003475b57e56e02b/

As you can see, the diagram is quite massive. But this architecture is considered the reference in OOP.


Conclusion

I hope this article was useful to you. If there are enough suggestions in the comments, I will write the second part of the article, where I will give examples of using all these collections. (Just imagine: at an interview they ask you about the hierarchy of collections in java, and you draw them the previous picture. How surprised they will be: D)
Thank you for your attention!!!

Email; Used to enter email addresses. This field automatically adds a check for the correctness of the email address; if the address is incorrect, an error is displayed. Telephone;Used to enter a telephone number. This field automatically adds a phone number check (numbers and some symbols). You can add a mask to your phone in the field settings. Name; Used to enter a name. A check is automatically applied to ensure that the field contains only letters. The symbols @, &, %, etc. will not be able to be entered. One line input field; Field for entering arbitrary text; no validation is applied when using the field. Multi-line input field; Field for entering arbitrary text in several lines, the field is increased in height. No validation is applied when using the field. Drop-down list; Field for selecting one of the answer options. Options are specified in advance in the block Content in the corresponding field, each option on a new line Question with answer options; A field for selecting options that are immediately visible under the field name. You can configure both the selection of one option (radio button) and several (checkmarks) Checkmark; A field to confirm any information from the user, usually used to agree to the privacy policy. File; Field for uploading a file from the user's side. To operate the field, you must register with the Uploadcare service and receive a key. Date of; Field for requesting a date from the user. When you use this type, a calendar widget appears next to the field from which you can select a date. In the field settings, you can select the date format and the type of separator - dot, hyphen or slash. There is an automatic check for the presence of numbers and correctness of input. Time; Field for requesting time in HH:MM format. On the published page, a colon appears in the field to ensure that the field is filled in correctly. Quantity (plus/minus buttons); Field for entering an arbitrary quantity or selecting using the plus and minus buttons. There is a check for numbers. Link; A field for entering a link to a page; there is an automatic check for the correctness of the link. Text comment; A system field type that is not an input field but serves to add additional information between fields on a form. Indent; A system field type that is not an input field, but serves to add space between fields. Hidden field; A system type of field in which you can write text that will allow you to identify the form, that is, determine that the application came from this particular form. The information is not shown to the user, but is transmitted to data receiving services.







2024 gtavrl.ru.