当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中org.cubeengine.dirigent.context.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于org.cubeengine.dirigent.context包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseFormatter

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
 * Parses the {@link NumberFormat} to use from the context arguments.
 *
 * @param context The context.
 * @param args The arguments of the macro.
 *
 * @return the {@link NumberFormat}.
 */
private NumberFormat parseFormatter(Context context, Arguments args)
{
    final String format = args.get(FORMAT_PARAM_NAME);
    final Locale locale = context.get(LOCALE);
    if (format != null)
    {
        return new DecimalFormat(format, DecimalFormatSymbols.getInstance(locale));
    }

    final Mode mode = Mode.loadFromContext(args, this.defaultMode);
    if (Mode.INTEGER.equals(mode))
    {
        return NumberFormat.getIntegerInstance(locale);
    }
    if (Mode.CURRENCY.equals(mode))
    {
        return NumberFormat.getCurrencyInstance(locale);
    }
    if (Mode.PERCENT.equals(mode))
    {
        return NumberFormat.getPercentInstance(locale);
    }
    return NumberFormat.getInstance(locale);
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:33,代码来源:NumberFormatter.java

示例2: buildAny

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
 * Appends a Component to the builder
 *
 * @param component the component
 * @param builder the builder
 * @param context the context
 */
protected final void buildAny(Component component, BuilderT builder, Context context)
{
    if (component instanceof ResolvedMacro)
    {
        buildResolved((ResolvedMacro)component, builder, context);
    }
    else if (component instanceof UnresolvableMacro)
    {
        buildUnresolvable((UnresolvableMacro)component, builder, context);
    }
    else if (component instanceof TextComponent)
    {
        buildText((TextComponent)component, builder, context);
    }
    else if (component instanceof ComponentGroup)
    {
        buildGroup((ComponentGroup)component, builder, context);
    }
    else
    {
        buildOther(component, builder, context);
    }
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:31,代码来源:MessageBuilder.java

示例3: parseFormatter

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
 * Parses the {@link DateFormat} to use from the context arguments.
 *
 * @param context The context.
 * @param args The arguments of the macro.
 *
 * @return the {@link DateFormat}.
 */
private DateFormat parseFormatter(Context context, Arguments args)
{
    final String format = args.get(FORMAT_PARAM_NAME);
    final Locale locale = context.get(LOCALE);
    if (format != null)
    {
        return new SimpleDateFormat(format, locale);
    }

    final int defaultFormatStyle = parseDateFormatStyle(args);
    final int dateFormatStyle = parseDateFormatStyle(args.get(DATE_PARAM_NAME), defaultFormatStyle);
    final int timeFormatStyle = parseDateFormatStyle(args.get(TIME_PARAM_NAME), defaultFormatStyle);

    if (Mode.DATE_TIME.equals(mode))
    {
        return DateFormat.getDateTimeInstance(dateFormatStyle, timeFormatStyle, locale);
    }
    else if (Mode.DATE.equals(mode))
    {
        return DateFormat.getDateInstance(dateFormatStyle, locale);
    }
    else if (Mode.TIME.equals(mode))
    {
        return DateFormat.getTimeInstance(timeFormatStyle, locale);
    }
    return DateFormat.getInstance();
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:36,代码来源:DateTimeFormatter.java

示例4: parseNumberToString

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
 * Parses the given number to a string depending on the context.
 *
 * @param number The number to parse.
 * @param context The context to use.
 * @param args The arguments of the macro.
 *
 * @return The number as a string.
 */
protected String parseNumberToString(Number number, Context context, Arguments args)
{
    final NumberFormat numberFormat = parseFormatter(context, args);

    final Currency currency = context.get(Contexts.CURRENCY);
    if (currency != null)
    {
        numberFormat.setCurrency(currency);
    }

    return numberFormat.format(number);
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:22,代码来源:NumberFormatter.java

示例5: format

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
protected Component format(final Object input, Context context, Arguments args)
{
    final Class<?> inputClass = input.getClass();
    final List<Formatter> candidates = new ArrayList<Formatter>();
    for (Entry<Class<?>, Formatter> entry : formats.entrySet())
    {
        Class<?> formatterClass = entry.getKey();
        if (inputClass == formatterClass)
        {
            // exact match will be used directly
            return this.formats.get(formatterClass).format(input, context, args);
        }
        else if (formatterClass.isAssignableFrom(inputClass))
        {
            candidates.add(entry.getValue());
        }
    }
    if (candidates.isEmpty())
    {
        return null;
    }
    Collections.sort(candidates, new Comparator<ReflectedFormatter.Formatter>()
    {
        @Override
        public int compare(ReflectedFormatter.Formatter a, ReflectedFormatter.Formatter b)
        {
            // sort descending, so the highest priority value will be first.
            return b.prio - a.prio;
        }
    });
    return candidates.get(0).format(input, context, args);
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:34,代码来源:ReflectedFormatter.java

示例6: compose

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
public MessageT compose(Context context, String source, Object... inputs)
{
    List<Element> elements = Parser.parse(source);
    ComponentGroup message = resolve(elements, context, inputs);
    return compose(message, context);
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:8,代码来源:AbstractDirigent.java

示例7: applyPostProcessors

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
 * Executes all attached {@link PostProcessor}s to process the specified {@link Component}.
 *
 * @param in The component to process.
 * @param context The compose context.
 * @param args The macro arguments.
 *
 * @return The processed component.
 */
private Component applyPostProcessors(Component in, Context context, Arguments args)
{
    Component out = in;

    for (final PostProcessor postProcessor : postProcessors)
    {
        out = postProcessor.process(out, context, args);
    }

    return out;
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:21,代码来源:AbstractDirigent.java

示例8: compose

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
protected MessageT compose(ComponentGroup componentGroup, Context context)
{
    BuilderT builder = mBuilder.newBuilder();
    mBuilder.buildGroup(componentGroup, builder, context);
    return mBuilder.finalize(builder, context);
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:8,代码来源:BuilderDirigent.java

示例9: buildUnresolvable

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
public void buildUnresolvable(UnresolvableMacro component, StringBuilder builder, Context context)
{
    Macro macro = component.getMacro();
    if (macro instanceof NamedMacro)
    {
        builder.append("{{unresolved: ").append(((NamedMacro)macro).getName()).append("}}");
    }
    else
    {
        builder.append("{{unresolved}}");
    }
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:14,代码来源:StringMessageBuilder.java

示例10: buildGroup

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
 * Appends a chain of Components to the builder
 *
 * @param group the chained Components
 * @param builder the builder
 * @param context the context
 */
public void buildGroup(ComponentGroup group, BuilderT builder, Context context)
{
    for (Component component : group.getComponents())
    {
        buildAny(component, builder, context);
    }
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:15,代码来源:MessageBuilder.java

示例11: checkFormat

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
private void checkFormat(final String expected, final Number number, final Locale locale, final Currency currency,
                         final String mode, final String value)
{
    final Context context = createContext(LOCALE.with(locale), CURRENCY.with(currency));
    final Arguments args = args(mode, value);
    final Component component = numberFormatter.format(number, context, args);

    Assert.assertTrue(component instanceof Text);
    Assert.assertEquals(expected, ((Text)component).getText());
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:11,代码来源:NumberFormatterTest.java

示例12: checkFormat

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
private void checkFormat(final String expected, final Date date, final Locale locale, final TimeZone timeZone,
                         final String defaultStyle, final String dateStyle, final String timeStyle,
                         final String format)
{
    final Context context = createContext(Contexts.LOCALE.with(locale), Contexts.TIMEZONE.with(timeZone));
    final Arguments args = createArguments(defaultStyle, dateStyle, timeStyle, format);

    final Component component = formatter.format(date, context, args);

    Assert.assertTrue(component instanceof Text);
    Assert.assertEquals(expected, ((Text)component).getText());
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:13,代码来源:AbstractDateTimeFormatterTest.java

示例13: testWrongParamsThreeParametersWithContext

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Test(expected = InvalidFormatMethodException.class)
public void testWrongParamsThreeParametersWithContext()
{
    @Names("test")
    class WrongParams extends ReflectedFormatter {
        @Format
        public Component test(String s, Context c, Integer i) {return null;}
    }

    new WrongParams();
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:12,代码来源:ReflectedFormatterTest.java

示例14: testWrongParamsMoreParameters

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Test(expected = InvalidFormatMethodException.class)
public void testWrongParamsMoreParameters()
{
    @Names("test")
    class WrongParams extends ReflectedFormatter {
        @Format
        public Component test(String s, Context c, Arguments a, Integer i) {return null;}
    }

    new WrongParams();
}
 
开发者ID:CubeEngine,项目名称:Dirigent,代码行数:12,代码来源:ReflectedFormatterTest.java

示例15: format

import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
public Component format(TeleportPoint object, Context context, Arguments args)
{
    String cmd = "/" + (object instanceof Home ? "home" : "warp") + " tp " + object.name + " " + object.getOwner().getName();
    return styled(UNDERLINE, runCommand(cmd, hoverText(i18n.translate(context, NONE, "Click to teleport to {}", object.name), object.getOwner().getName())));
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:7,代码来源:TpPointFormatter.java


注:本文中的org.cubeengine.dirigent.context.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。