Java Code Examples for java.util.Collections#EMPTY_MAP

The following examples show how to use java.util.Collections#EMPTY_MAP . These examples are extracted from open source projects. 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 Project: canal   File: UriUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Map<String, String> parseQuery(final URI uri, final String encoding) {
    if (uri == null || StringUtils.isBlank(uri.getQuery())) {
        return Collections.EMPTY_MAP;
    }
    String query = uri.getRawQuery();
    HashMap<String, String> params = new HashMap<String, String>();
    @SuppressWarnings("resource")
    Scanner scan = new Scanner(query);
    scan.useDelimiter(SPLIT);
    while (scan.hasNext()) {
        String token = scan.next().trim();
        String[] pair = token.split(EQUAL);
        String key = decode(pair[0], encoding);
        String value = null;
        if (pair.length == 2) {
            value = decode(pair[1], encoding);
        }
        params.put(key, value);
    }
    return params;
}
 
Example 2
@Override
public Map getRequestCookieMap() {
    Map requestCookieMap = (Map) requestCookieMaps.get();
    if (requestCookieMap == null) {
        requestCookieMap = Collections.EMPTY_MAP;
        requestCookieMaps.set(requestCookieMap);
    }
    return requestCookieMap;
}
 
Example 3
@Override
    public CompileResult<ApplesoftProgram> compile(Program program) {
        final ApplesoftProgram result = ApplesoftProgram.fromString(program.getValue());
        final Map<Integer, String> warnings = new LinkedHashMap<>();
//        int lineNumber = 1;
//        for (Line l : result.lines) {
//            warnings.put(lineNumber++, l.toString());
//        }
        return new CompileResult<ApplesoftProgram>() {
            @Override
            public boolean isSuccessful() {
                return result != null;
            }

            @Override
            public ApplesoftProgram getCompiledAsset() {
                return result;
            }

            @Override
            public Map<Integer, String> getErrors() {
                return Collections.EMPTY_MAP;
            }

            @Override
            public Map<Integer, String> getWarnings() {
                return warnings;
            }

            @Override
            public List<String> getOtherMessages() {
                return Collections.EMPTY_LIST;
            }

            @Override
            public List<String> getRawOutput() {
                return Collections.EMPTY_LIST;
            }
        };
    }
 
Example 4
Source Project: birt   File: AbstractViewer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected long createReportOutput( String reportDocumentFile,
		String outputFile, long pageNumber ) throws EngineException,
		IOException
{
	IReportDocument document = engine.openReportDocument( reportDocumentFile );
	long pageCount = document.getPageCount( );
	IRenderTask task = engine.createRenderTask( document );

	IRenderOption renderOption = getRenderOption( );
	renderOption.setOutputFileName( outputFile );

	try
	{
		task.setRenderOption( renderOption );
		task.setPageNumber( pageNumber );
		Map appContext = Collections.EMPTY_MAP;
		if(ExtendedDataModelUIAdapterHelper.getInstance( ).getAdapter( ) != null)
		{
			appContext = ExtendedDataModelUIAdapterHelper.getInstance( ).getAdapter( ).getAppContext( );
		}
		task.setAppContext( appContext );
		task.render( );
	}
	catch ( EngineException e )
	{
		throw e;
	}
	finally
	{
		task.close( );
		task = null;
		document.close( );
		document = null;
	}
	return pageCount;
}
 
Example 5
Source Project: groovy   File: VariableScope.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets a map containing the variables declared in this scope. This map cannot be modified.
 *
 * @return a map containing the declared variable references
 */
public Map<String, Variable> getDeclaredVariables() {
    if (declaredVariables == Collections.EMPTY_MAP) {
        return declaredVariables;
    } else {
        return Collections.unmodifiableMap(declaredVariables);
    }
}
 
Example 6
Source Project: groovy-cps   File: ClosureCallEnv.java    License: Apache License 2.0 5 votes vote down vote up
public void declareVariable(Class type, String name) {
    if (locals == Collections.EMPTY_MAP) {
        locals = new HashMap<String, Object>(2);
    }
    locals.put(name, null);
    getTypesForMutation().put(name, type);
}
 
Example 7
/**
 * {@inheritDoc}
 */
@Override
@BeanTagAttribute
public Map<String, String> getScriptDataAttributes() {
    if (scriptDataAttributes == Collections.EMPTY_MAP) {
        scriptDataAttributes = new HashMap<String, String>();
    }

    return scriptDataAttributes;
}
 
Example 8
@Override
public Map<String, CheckpointableWatermark> getAllUnacknowledgedWatermarks() {
  if (_unackedWatermarkMap != null) {
    return new HashMap<>(_unackedWatermarkMap);
  } else {
    return Collections.EMPTY_MAP;
  }
}
 
Example 9
Source Project: usergrid   File: RequestCursor.java    License: Apache License 2.0 5 votes vote down vote up
public RequestCursor( final Optional<String> cursor ) {
    if ( cursor.isPresent() ) {
        parsedCursor = fromCursor( cursor.get() );
    }
    else {
        parsedCursor = Collections.EMPTY_MAP;
    }
}
 
Example 10
Source Project: datacollector   File: TestStageContext.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyException() throws EmailException {

  EmailSender sender = Mockito.mock(EmailSender.class);
  Mockito.doThrow(StageException.class)
      .when(sender)
      .send(Mockito.anyList(), Mockito.anyString(), Mockito.anyString());

  StageContext context = new StageContext(
    "stage",
    StageType.SOURCE,
    -1,
    false,
    OnRecordError.TO_ERROR,
    Collections.EMPTY_LIST,
    Collections.EMPTY_MAP,
    Collections.<String, Object> emptyMap(),
    ExecutionMode.STANDALONE,
    DeliveryGuarantee.AT_LEAST_ONCE,
    null,
    sender,
    new Configuration(),
    new LineagePublisherDelegator.NoopDelegator(),
    Mockito.mock(RuntimeInfo.class),
    Collections.emptyMap()
  );

  try {
    context.notify(ImmutableList.of("foo", "bar"), "SUBJECT", "BODY");
    fail("Expected StageException");
  } catch (StageException e) {

  }

}
 
Example 11
@Override
public Map<String, Map<MessageQueue, Long>> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException,
    MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    if (brokerDatas != null && brokerDatas.size() > 0) {
        String addr = brokerDatas.get(0).selectBrokerAddr();
        if (addr != null) {
            return this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToGetConsumerStatus(addr, topic, group, clientAddr,
                timeoutMillis);
        }
    }
    return Collections.EMPTY_MAP;
}
 
Example 12
Source Project: pulsar   File: NamespaceEphemeralData.java    License: Apache License 2.0 5 votes vote down vote up
public NamespaceEphemeralData(String brokerUrl, String brokerUrlTls, String httpUrl, String httpUrlTls,
                              boolean disabled, Map<String, AdvertisedListener> advertisedListeners) {
    this.nativeUrl = brokerUrl;
    this.nativeUrlTls = brokerUrlTls;
    this.httpUrl = httpUrl;
    this.httpUrlTls = httpUrlTls;
    this.disabled = disabled;
    if (advertisedListeners == null) {
        this.advertisedListeners = Collections.EMPTY_MAP;
    } else {
        this.advertisedListeners = Maps.newHashMap(advertisedListeners);
    }
}
 
Example 13
Source Project: onetwo   File: ReflectUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> field2Map(Object obj, BiFunction<Field, Object, Boolean> acceptor) {
	if (obj == null)
		return Collections.EMPTY_MAP;
	Collection<Field> fields = findFieldsFilterStatic(obj.getClass());
	if (fields == null || fields.isEmpty())
		return Collections.EMPTY_MAP;
	Map<String, Object> rsMap = new HashMap();
	Object val = null;
	for (Field field : fields) {
		val = getFieldValue(field, obj, false);
		if (acceptor.apply(field, val))
			rsMap.put(field.getName(), val);
	}
	return rsMap;
}
 
Example 14
Source Project: spring-boot   File: MyDbUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 根据传入的sql,查询记录,以Map形式返回第一行记录。 注意:如果有多行记录,只会返回第一行,所以适用场景需要注意,可以使用根据主键来查询的场景
 *
 * @param sql
 * @return
 */
public static Map<String, Object> getFirstRowMap(String sql) {
    try {
        // MapHandler 将ResultSet的首行转换为一个Map的ResultSetHandler实现类
        return queryRunner.query(sql, new MapHandler());
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return Collections.EMPTY_MAP;
}
 
Example 15
Source Project: Tomcat8-Source-Read   File: ELSupport.java    License: MIT License 4 votes vote down vote up
public static final Object coerceToType(final ELContext ctx, final Object obj,
        final Class<?> type) throws ELException {

    if (ctx != null) {
        boolean originalIsPropertyResolved = ctx.isPropertyResolved();
        try {
            Object result = ctx.getELResolver().convertToType(ctx, obj, type);
            if (ctx.isPropertyResolved()) {
                return result;
            }
        } finally {
            ctx.setPropertyResolved(originalIsPropertyResolved);
        }
    }

    if (type == null || Object.class.equals(type) ||
            (obj != null && type.isAssignableFrom(obj.getClass()))) {
        return obj;
    }

    if (!COERCE_TO_ZERO) {
        if (obj == null && !type.isPrimitive() &&
                !String.class.isAssignableFrom(type)) {
            return null;
        }
    }

    if (String.class.equals(type)) {
        return coerceToString(ctx, obj);
    }
    if (ELArithmetic.isNumberType(type)) {
        return coerceToNumber(ctx, obj, type);
    }
    if (Character.class.equals(type) || Character.TYPE == type) {
        return coerceToCharacter(ctx, obj);
    }
    if (Boolean.class.equals(type) || Boolean.TYPE == type) {
        return coerceToBoolean(ctx, obj, Boolean.TYPE == type);
    }
    if (type.isEnum()) {
        return coerceToEnum(ctx, obj, type);
    }

    // new to spec
    if (obj == null)
        return null;
    if (obj instanceof String) {
        PropertyEditor editor = PropertyEditorManager.findEditor(type);
        if (editor == null) {
            if ("".equals(obj)) {
                return null;
            }
            throw new ELException(MessageFactory.get("error.convert", obj,
                    obj.getClass(), type));
        } else {
            try {
                editor.setAsText((String) obj);
                return editor.getValue();
            } catch (RuntimeException e) {
                if ("".equals(obj)) {
                    return null;
                }
                throw new ELException(MessageFactory.get("error.convert",
                        obj, obj.getClass(), type), e);
            }
        }
    }

    // Handle special case because the syntax for the empty set is the same
    // for an empty map. The parser will always parse {} as an empty set.
    if (obj instanceof Set && type == Map.class &&
            ((Set<?>) obj).isEmpty()) {
        return Collections.EMPTY_MAP;
    }

    // Handle arrays
    if (type.isArray() && obj.getClass().isArray()) {
        return coerceToArray(ctx, obj, type);
    }

    throw new ELException(MessageFactory.get("error.convert",
            obj, obj.getClass(), type));
}
 
Example 16
Source Project: killbill-api   File: Healthcheck.java    License: Apache License 2.0 4 votes vote down vote up
public static HealthStatus healthy() {
    return new HealthStatus(true, Collections.EMPTY_MAP);
}
 
Example 17
Source Project: gemfirexd-oss   File: FilterProfile.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return the patternsOfInterestInv
 */
private Map<Object, Map<Object, Pattern>> getPatternsOfInterestInv() {
  Map<Object, Map<Object, Pattern>> patternsOfInterestInvRef = this.patternsOfInterestInv;
  return patternsOfInterestInvRef == null? Collections.EMPTY_MAP : patternsOfInterestInvRef;
}
 
Example 18
public Set<String> getUnicodeLocaleKeys() {
    if (keywords == Collections.EMPTY_MAP) {
        return Collections.emptySet();
    }
    return Collections.unmodifiableSet(keywords.keySet());
}
 
Example 19
Source Project: sis   File: Numbers.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns a {@code NaN}, zero, empty or {@code null} value of the given type. This method
 * tries to return the closest value that can be interpreted as <cite>"none"</cite>, which
 * is usually not the same than <cite>"zero"</cite>. More specifically:
 *
 * <ul>
 *   <li>If the given type is a floating point <strong>primitive</strong> type ({@code float}
 *       or {@code double}), then this method returns {@link Float#NaN} or {@link Double#NaN}
 *       depending on the given type.</li>
 *
 *   <li>If the given type is an integer <strong>primitive</strong> type or the character type
 *       ({@code long}, {@code int}, {@code short}, {@code byte} or {@code char}), then this
 *       method returns the zero value of the given type.</li>
 *
 *   <li>If the given type is the {@code boolean} <strong>primitive</strong> type, then this
 *       method returns {@link Boolean#FALSE}.</li>
 *
 *   <li>If the given type is an array or a collection, then this method returns an empty
 *       array or collection. The given type is honored on a <cite>best effort</cite> basis.</li>
 *
 *   <li>For all other cases, including the wrapper classes of primitive types, this method
 *       returns {@code null}.</li>
 * </ul>
 *
 * Despite being defined in the {@code Numbers} class, the scope of this method has been
 * extended to array and collection types because those objects can also be seen as
 * mathematical concepts.
 *
 * @param  <T>   the compile-time type of the requested object.
 * @param  type  the type of the object for which to get a nil value.
 * @return an object of the given type which represents a nil value, or {@code null}.
 *
 * @see org.apache.sis.xml.NilObject
 */
@SuppressWarnings("unchecked")
public static <T> T valueOfNil(final Class<T> type) {
    final Numbers mapping = MAPPING.get(type);
    if (mapping != null) {
        if (type.isPrimitive()) {
            return (T) mapping.nullValue;
        }
    } else if (type != null && type != Object.class) {
        if (type == Map         .class) return (T) Collections.EMPTY_MAP;
        if (type == List        .class) return (T) Collections.EMPTY_LIST;
        if (type == Queue       .class) return (T) CollectionsExt.emptyQueue();
        if (type == SortedSet   .class) return (T) Collections.emptySortedSet();
        if (type == NavigableSet.class) return (T) Collections.emptyNavigableSet();
        if (type.isAssignableFrom(Set.class)) {
            return (T) Collections.EMPTY_SET;
        }
        final Class<?> element = type.getComponentType();
        if (element != null) {
            return (T) Array.newInstance(element, 0);
        }
    }
    return null;
}
 
Example 20
Source Project: big-c   File: KeyProvider.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, String> getAttributes() {
  return (attributes == null) ? Collections.EMPTY_MAP : attributes;
}