javax.ws.rs.core.Variant.VariantListBuilder Java Examples

The following examples show how to use javax.ws.rs.core.Variant.VariantListBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VariantListBuilderImpl.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public VariantListBuilder add() {
    checkState(!(mediaTypes.isEmpty() && languages.isEmpty() && encodings.isEmpty()),
               "At least one media type, language or encoding must be set");

    if (variants == null) {
        variants = new ArrayList<>();
    }

    Iterator<MediaType> mediaTypesIterator = mediaTypes.iterator();
    do {
        MediaType mediaType = mediaTypesIterator.hasNext() ? mediaTypesIterator.next() : null;
        Iterator<Locale> languagesIterator = languages.iterator();
        do {
            Locale language = languagesIterator.hasNext() ? languagesIterator.next() : null;
            Iterator<String> encodingsIterator = encodings.iterator();
            do {
                String encoding = encodingsIterator.hasNext() ? encodingsIterator.next() : null;
                variants.add(new Variant(mediaType, language, encoding));
            } while (encodingsIterator.hasNext());
        } while (languagesIterator.hasNext());
    } while (mediaTypesIterator.hasNext());

    clearAll();
    return this;
}
 
Example #2
Source File: RuntimeDelegateImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public <T> T createInstance(Class<T> type) {
    if (type.isAssignableFrom(ResponseBuilder.class)) {
        return type.cast(new ResponseBuilderImpl());
    }
    if (type.isAssignableFrom(UriBuilder.class)) {
        return type.cast(new UriBuilderImpl());
    }
    if (type.isAssignableFrom(VariantListBuilder.class)) {
        return type.cast(new VariantListBuilderImpl());
    }
    return null;
}
 
Example #3
Source File: RuntimeDelegateImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateInstance() throws Exception {
    assertSame(ResponseBuilderImpl.class,
               new RuntimeDelegateImpl().
                   createInstance(ResponseBuilder.class).getClass());
    assertSame(UriBuilderImpl.class,
               new RuntimeDelegateImpl().
                   createInstance(UriBuilder.class).getClass());
    assertSame(VariantListBuilderImpl.class,
               new RuntimeDelegateImpl().
                   createInstance(VariantListBuilder.class).getClass());
}
 
Example #4
Source File: ResponseImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static List<Variant> getVariantList(List<String> encoding,
                                              MediaType... mt) {
    return Variant.VariantListBuilder.newInstance()
        .mediaTypes(mt)
        .languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN"))
        .encodings(encoding.toArray(new String[]{}))
        .add()
        .build();
}
 
Example #5
Source File: MSF4JRuntimeDelegate.java    From msf4j with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder createVariantListBuilder() {
    throw new UnsupportedOperationException();
}
 
Example #6
Source File: RuntimeDelegateImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder createVariantListBuilder() {
    return new VariantListBuilderImpl();
}
 
Example #7
Source File: VariantListBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder add() {
    addVariants();
    resetMeta();
    return this;
}
 
Example #8
Source File: VariantListBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder encodings(String... encs) {
    Collections.addAll(encodings, encs);
    return this;
}
 
Example #9
Source File: VariantListBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder mediaTypes(MediaType... types) {
    Collections.addAll(mediaTypes, types);
    return this;
}
 
Example #10
Source File: VariantListBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder languages(Locale... ls) {
    Collections.addAll(languages, ls);
    return this;
}
 
Example #11
Source File: ResponseImplTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder createVariantListBuilder() {
    return original.createVariantListBuilder();
}
 
Example #12
Source File: RuntimeDelegateImpl.java    From everrest with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder createVariantListBuilder() {
    return new VariantListBuilderImpl();
}
 
Example #13
Source File: RuntimeDelegateImpl.java    From cougar with Apache License 2.0 4 votes vote down vote up
@Override
public VariantListBuilder createVariantListBuilder() {
    throw new UnsupportedOperationException();
}