Example usage for java.util EnumMap EnumMap

List of usage examples for java.util EnumMap EnumMap

Introduction

In this page you can find the example usage for java.util EnumMap EnumMap.

Prototype

public EnumMap(Map<K, ? extends V> m) 

Source Link

Document

Creates an enum map initialized from the specified map.

Usage

From source file:com.tomtom.speedtools.json.JsonTest.java

@Test
public void testJsonEnumMap() throws Exception {
    LOG.info("testJsonEnumMap");

    final Map<MyEnumType, Integer> x = new EnumMap<>(MyEnumType.class);
    x.put(MyEnumType.A, 100);/*from   w  w w  .  j av a  2s.  c o  m*/
    x.put(MyEnumType.B, 200);
    x.put(MyEnumType.C, 300);
    x.put(MyEnumType.D, 400);

    final String s = Json.toJson(x);
    LOG.info("x.toJson = {}", s);
    Assert.assertEquals("{\"A\":100,\"B\":200,\"C\":300,\"D\":400}", s);
}

From source file:com.hp.autonomy.frontend.find.hod.fields.HodFieldsControllerTest.java

@Override
@Test//from  w ww  .  j  a  v a  2s  . co  m
public void getParametricDateFields() throws HodErrorException {
    final Map<FieldTypeParam, List<TagName>> response = new EnumMap<>(FieldTypeParam.class);
    response.put(FieldTypeParam.NumericDate,
            ImmutableList.of(new TagName("DateField"), new TagName("ParametricDateField")));
    response.put(FieldTypeParam.Parametric, ImmutableList.of(new TagName("ParametricField"),
            new TagName("ParametricNumericField"), new TagName("ParametricDateField")));
    when(service.getFields(Matchers.<HodFieldsRequest>any(), eq(FieldTypeParam.Parametric),
            eq(FieldTypeParam.NumericDate))).thenReturn(response);

    final ValueDetails valueDetails = new ValueDetails.Builder().setMin(146840000d).setMax(146860000d)
            .setAverage(146850000d).setSum(1046850000d).setTotalValues(1000).build();

    final Map<TagName, ValueDetails> valueDetailsOutput = ImmutableMap.<TagName, ValueDetails>builder()
            .put(new TagName("ParametricDateField"), valueDetails).build();

    when(parametricValuesService.getValueDetails(Matchers.<HodParametricRequest>any()))
            .thenReturn(valueDetailsOutput);

    final List<FieldAndValueDetails> fields = controller.getParametricDateFields(createRequest());
    assertThat(fields, hasSize(1));
    assertThat(fields, hasItem(is(new FieldAndValueDetails("ParametricDateField", "ParametricDateField",
            146840000d, 146860000d, 1000))));
}

From source file:net.sourceforge.cobertura.metrics.model.coverage.scope.AbstractCoverageScope.java

/**
 * Compound constructor invoked by subclasses.
 * The constructor will, in turn, call the template setup method {@code setupPatternMap} to configure
 * the patternMap./*from  w w w.ja  v a  2  s  .  c o  m*/
 *
 * @param name The human-readable name of this AbstractCoverageScope instance,
 *             such as the fully qualified package or class name.
 * @throws java.lang.IllegalStateException if the patternMap, populated from the {@code setupPatternMap} method
 * held null patterns.
 */
protected AbstractCoverageScope(final String name) throws IllegalStateException {

    // Check sanity
    Validate.notEmpty(name, "Cannot handle null or empty name argument.");

    // Assign internal state
    this.name = name;
    this.patternMap = new EnumMap<LocationScope, Pattern>(LocationScope.class);
    patternMap.put(LocationScope.PROJECT, Pattern.compile("\\*"));

    // Acquire the pattern map and validate its content
    setupPatternMap(patternMap);

    // Copy all Patterns to the patterns List
    for (Map.Entry<LocationScope, Pattern> current : patternMap.entrySet()) {
        patterns.add(current.getValue().pattern());
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicShortTermCombinedTripleSource.java

private Map<WhichService, RDFService> populateRdfServicesMap() {
    Map<WhichService, RDFService> map = new EnumMap<>(WhichService.class);
    for (WhichService which : WhichService.values()) {
        map.put(which, parent.getRDFServiceFactory(which).getShortTermRDFService());
    }/*from   w  w w  . j  a  v  a 2s. co m*/
    return Collections.unmodifiableMap(map);
}

From source file:alma.acs.nc.sm.generic.AcsScxmlActionDispatcher.java

public AcsScxmlActionDispatcher(Logger logger, Class<A> actionType) {
    this.logger = logger;
    this.actionType = actionType;
    actionMap = new EnumMap<A, AcsScxmlActionExecutor<A>>(actionType);
}

From source file:org.leandreck.endpoints.processor.model.TypeNodeFactory.java

private Map<TypeNodeKind, ConcreteTypeNodeFactory> initFactories() {
    final Map<TypeNodeKind, ConcreteTypeNodeFactory> tmpFactories = new EnumMap<>(TypeNodeKind.class);
    Arrays.stream(TypeNodeKind.values()).forEach(it -> {
        try {//  ww  w .ja v a  2 s.c o m
            tmpFactories.put(it, it.getTypeNodeFactory().newConfiguredInstance(this, this.configuration,
                    this.typeUtils, this.elementUtils));
        } catch (final Exception e) {
            throw new InitTypeNodeFactoriesException(e);
        }
    });
    return tmpFactories;
}

From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessIfaceQrCodeActivity.java

@Nullable
private static Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int imgWidth, int imgHeight)
        throws WriterException {
    if (contents == null) {
        return null;
    }//from   w  w  w .  ja  va 2 s .co  m
    Map<EncodeHintType, Object> hints = null;
    final String encoding = guessAppropriateEncoding(contents);
    if (encoding != null) {
        hints = new EnumMap<>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    final MultiFormatWriter writer = new MultiFormatWriter();
    final BitMatrix result;
    try {
        result = writer.encode(contents, format, imgWidth, imgHeight, hints);
    } catch (IllegalArgumentException iae) {
        // Unsupported format
        return null;
    }
    final int width = result.getWidth();
    final int height = result.getHeight();
    final int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        final int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
        }
    }

    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);

    return bitmap;
}

From source file:com.moviejukebox.model.artwork.Artwork.java

/**
 * Create an Artwork object with a single size
 *
 * @param type The type of the artwork//from  w w w .j a v a  2 s  .  c  o  m
 * @param sourceSite The source site the artwork came from
 * @param url The URL of the artwork
 * @param size An artwork files to add
 */
public Artwork(ArtworkType type, String sourceSite, String url, ArtworkFile size) {
    this.type = type;
    this.sourceSite = sourceSite;
    this.url = url;
    this.sizes = new EnumMap<>(ArtworkSize.class);
    this.addSize(size);
}

From source file:net.sf.reportengine.core.algorithm.report.TestDefaultLoopThroughTableInputAlgo.java

/**
 * Test method for/*w  ww  .  ja  v  a  2s.  c o  m*/
 * {@link net.sf.reportengine.core.algorithm.report.LoopThroughTableInputAlgo#execute()}
 * .
 */
@Test
public void testExecuteAlgorithm() {
    Map<AlgoIOKeys, Object> mockAlgoInput = new EnumMap<AlgoIOKeys, Object>(AlgoIOKeys.class);
    mockAlgoInput.put(AlgoIOKeys.TABLE_INPUT, testInput);
    // mockAlgoInput.put(IOKeys.REPORT_OUTPUT, testOut);

    Map<AlgoIOKeys, Object> algoResult = classUnderTest.execute(mockAlgoInput);
    Assert.assertEquals(Integer.valueOf(2), (Integer) algoResult.get(AlgoIOKeys.TEST_KEY));
}

From source file:tasly.greathealth.oms.inventory.services.impl.DefaultItemQuantityService.java

@Override
@Transactional/*from w ww .  j a va2 s. c  o  m*/
public EnumMap<HandleReturn, Object> handleUpdateMethod(
        final List<TaslyItemLocationData> taslyItemLocationDatas, final String sku, final int flag,
        final int totalNumber) {
    final EnumMap<HandleReturn, Object> retMap = new EnumMap<HandleReturn, Object>(HandleReturn.class);
    boolean status = true;
    boolean flagStatus = false;// insert new itemQuantity flagStatus.
    int totalOccupy = 0;
    try {
        for (int i = 0; i < taslyItemLocationDatas.size(); i++) {
            final List<ItemQuantityData> itemQuantityDatas = taslyItemLocationDatas.get(i).getItemQuantities();
            if (itemQuantityDatas == null || itemQuantityDatas.size() == 0)// no itemQuantityDatas, create!
            {
                final CurrentItemQuantityData currentItemQuantityData = getPersistenceManager()
                        .create(CurrentItemQuantityData.class);
                currentItemQuantityData.setQuantityValue(0);
                currentItemQuantityData.setStatusCode("ON_HAND");
                currentItemQuantityData.setOwner(taslyItemLocationDatas.get(i));
                flagStatus = true;
            } else if (itemQuantityDatas.size() > 0 && flag == 0)// flag=0 itemQuantityData exist,no need update
            {
                status = false;
            } else
            // itemQuantityDatas exist, check number
            {
                final ItemQuantityData iqd = checkItemQuantitySatus(itemQuantityDatas);
                if (iqd == null) {
                    omsLOG.info("There is no on_hand data!");
                    status = false;
                    break;
                }
                final StockroomLocationData sld = taslyItemLocationDatas.get(i).getStockroomLocation();
                final int occupy = iqd.getQuantityValue() - calculateAts(sld, sku);
                totalOccupy = totalOccupy + occupy;

                // omsLOG.info("Sku:" + sku + ",LocationId:" + locationId + ",Assign value:"
                // + (int) Math.round(totalNumber * taslyItemLocationDatas.get(i).getAllocationPercent() / 100.0)
                // + ",Get value:" + iqd.getQuantityValue() + ",Ats value:" + atsResult.getResult(sku, atsId,
                // locationId));
                // if ((int) Math.round(totalNumber * taslyItemLocationDatas.get(i).getAllocationPercent() / 100.0) <
                // occupy)
                // {
                // omsLOG.error("SKU:" + sku + ",LocationId:" + locationId +
                // ",occupy number bigger than pre assigned value!");
                // // status = false;
                // }// this sku all ItemLocations skipped!
            }
        }
    } catch (final Exception e) {
        omsLOG.error("error is " + e);
    }
    if (flag == 0 && flagStatus)// flag = 0 and insert new itemQuantity need to be assign.
    {
        retMap.put(HandleReturn.handleStatus, true);
        retMap.put(HandleReturn.availableNumber, 0);
        retMap.put(HandleReturn.errorStatus, false);
        return retMap;
    } else {
        retMap.put(HandleReturn.handleStatus, status);
        retMap.put(HandleReturn.availableNumber, totalNumber - totalOccupy);
        if (totalNumber < totalOccupy) {
            omsLOG.error("SKU:" + sku + ",totalNumber:" + totalNumber + ",<,totalOccupy:" + totalOccupy);
            retMap.put(HandleReturn.errorStatus, true);
        } else {
            retMap.put(HandleReturn.errorStatus, false);
        }
        return retMap;
    }
}