List of usage examples for java.util EnumMap EnumMap
public EnumMap(Map<K, ? extends V> m)
From source file:org.talend.mdm.commmon.metadata.compare.HibernateStorageImpactAnalyzer.java
public Map<Impact, List<Change>> analyzeImpacts(Compare.DiffResults diffResult) { Map<Impact, List<Change>> impactSort = new EnumMap<Impact, List<Change>>(Impact.class); for (Impact impact : Impact.values()) { impactSort.put(impact, new LinkedList<Change>()); }//from w w w. java2s . c o m // Add actions for (AddChange addAction : diffResult.getAddChanges()) { MetadataVisitable element = addAction.getElement(); if (element instanceof ComplexTypeMetadata) { impactSort.get(Impact.LOW).add(addAction); } else if (element instanceof FieldMetadata) { if (element instanceof ContainedTypeFieldMetadata) { // Contained field may change mapping strategy impactSort.get(Impact.HIGH).add(addAction); } else { String defaultValueRule = ((FieldMetadata) element) .getData(MetadataRepository.DEFAULT_VALUE_RULE); // TMDM-7895: Newly added element and mandatory should be considered as "high" change if (((FieldMetadata) element).isMandatory() && StringUtils.isBlank(defaultValueRule)) { impactSort.get(Impact.HIGH).add(addAction); } else { impactSort.get(Impact.LOW).add(addAction); } } } } // Remove actions for (RemoveChange removeAction : diffResult.getRemoveChanges()) { MetadataVisitable element = removeAction.getElement(); if (element instanceof ComplexTypeMetadata) { impactSort.get(Impact.MEDIUM).add(removeAction); } else if (element instanceof FieldMetadata) { FieldMetadata field = (FieldMetadata) removeAction.getElement(); if (field.isMandatory()) { impactSort.get(Impact.HIGH).add(removeAction); } else { impactSort.get(Impact.MEDIUM).add(removeAction); } } else { throw new NotImplementedException(); } } // Modify actions for (ModifyChange modifyAction : diffResult.getModifyChanges()) { MetadataVisitable element = modifyAction.getElement(); if (element instanceof ComplexTypeMetadata) { // Type modifications may include many things (inheritance changes for instance). impactSort.get(Impact.HIGH).add(modifyAction); } else if (element instanceof FieldMetadata) { FieldMetadata previous = (FieldMetadata) modifyAction.getPrevious(); FieldMetadata current = (FieldMetadata) modifyAction.getCurrent(); // TMDM-9909: Increase the length of a string element should be low impact Object previousLength = CommonUtil.getSuperTypeMaxLength(previous.getType(), previous.getType()); Object currentLength = CommonUtil.getSuperTypeMaxLength(current.getType(), current.getType()); // TMDM-8022: issues about custom decimal type totalDigits/fractionDigits. Object previousTotalDigits = previous.getType().getData(MetadataRepository.DATA_TOTAL_DIGITS); Object currentTotalDigits = current.getType().getData(MetadataRepository.DATA_TOTAL_DIGITS); Object previousFractionDigits = previous.getType().getData(MetadataRepository.DATA_FRACTION_DIGITS); Object currentFractionDigits = current.getType().getData(MetadataRepository.DATA_FRACTION_DIGITS); /* * HIGH IMPACT CHANGES */ if (element instanceof SimpleTypeFieldMetadata && MetadataUtils.getSuperConcreteType(((FieldMetadata) element).getType()).getName() .equals("string") && Integer.valueOf((String) (currentLength == null ? STRING_DEFAULT_LENGTH : currentLength)) .compareTo(Integer.valueOf((String) (previousLength == null ? STRING_DEFAULT_LENGTH : previousLength))) > 0) { impactSort.get(Impact.LOW).add(modifyAction); } else if (!ObjectUtils.equals(previousLength, currentLength)) { // Won't be able to change constraint for max length impactSort.get(Impact.HIGH).add(modifyAction); } else if (!ObjectUtils.equals(previousTotalDigits, currentTotalDigits)) { // TMDM-8022: issues about custom decimal type totalDigits/fractionDigits. impactSort.get(Impact.HIGH).add(modifyAction); } else if (!ObjectUtils.equals(previousFractionDigits, currentFractionDigits)) { // TMDM-8022: issues about custom decimal type totalDigits/fractionDigits. impactSort.get(Impact.HIGH).add(modifyAction); } else if (!previous.getType().equals(current.getType())) { TypeMetadata superPreviousType = MetadataUtils.getSuperConcreteType(previous.getType()); TypeMetadata superCurrentType = MetadataUtils.getSuperConcreteType(current.getType()); if (superPreviousType == null) { throw new IllegalStateException( "Unable to find super type of '" + previous.getType().getName() + "'."); } if (superPreviousType.equals(superCurrentType)) { // TMDM-7748: Type modification is ok as long as the super type remains the same. impactSort.get(Impact.LOW).add(modifyAction); } else { // Type modification has high impact (values might not be following correct format). impactSort.get(Impact.HIGH).add(modifyAction); } } else if (previous.isMany() != current.isMany()) { // Collection mapping undo (or creation) has a high impact on schema impactSort.get(Impact.HIGH).add(modifyAction); } else if (previous.isKey() != current.isKey()) { // Key creation might have high impact (in case of duplicated values). impactSort.get(Impact.HIGH).add(modifyAction); } else if (previous.isMandatory() != current.isMandatory()) { if (!previous.isMandatory() && current.isMandatory()) { // Won't be able to change constraint String defaultValueRule = ((FieldMetadata) current) .getData(MetadataRepository.DEFAULT_VALUE_RULE); if (!modifyAction.isHasNullValue()) { impactSort.get(Impact.LOW).add(modifyAction); } else if (modifyAction.isHasNullValue() && StringUtils.isBlank(defaultValueRule)) { impactSort.get(Impact.HIGH).add(modifyAction); } else if (modifyAction.isHasNullValue() && StringUtils.isNotBlank(defaultValueRule)) { impactSort.get(Impact.MEDIUM).add(modifyAction); } } else if (previous.isMandatory() && !current.isMandatory()) { impactSort.get(Impact.LOW).add(modifyAction); } } if (previous instanceof ReferenceFieldMetadata) { if (current instanceof ReferenceFieldMetadata) { ReferenceFieldMetadata previousFieldMetadata = (ReferenceFieldMetadata) previous; ReferenceFieldMetadata currentFieldMetadata = (ReferenceFieldMetadata) current; if (!previousFieldMetadata.getReferencedType().getName() .equals(currentFieldMetadata.getReferencedType().getName())) { impactSort.get(Impact.HIGH).add(modifyAction); } } else { impactSort.get(Impact.HIGH).add(modifyAction); } } } } return impactSort; }
From source file:com.almende.pi5.common.FlexDirection.java
/** * Map of./*from w w w . j av a2s.c o m*/ * * @param up * the up * @param down * the down * @return the map */ public static Map<FlexDirection, FlexRange> mapOf(final FlexRange up, final FlexRange down) { final Map<FlexDirection, FlexRange> result = new EnumMap<>(FlexDirection.class); result.put(FlexDirection.DOWNWARD, down); result.put(FlexDirection.UPWARD, up); return result; }
From source file:nl.strohalm.cyclos.controls.groups.ListGroupsAction.java
/** * @return a map with from group's nature to the corresponding manage group permission *///from w w w.j a v a 2 s.co m public static Map<Group.Nature, Permission> getManageGroupPermissionByNatureMap() { final Map<Group.Nature, Permission> permissionByNature = new EnumMap<Group.Nature, Permission>( Group.Nature.class); permissionByNature.put(Group.Nature.ADMIN, AdminSystemPermission.GROUPS_MANAGE_ADMIN); permissionByNature.put(Group.Nature.BROKER, AdminSystemPermission.GROUPS_MANAGE_BROKER); permissionByNature.put(Group.Nature.MEMBER, AdminSystemPermission.GROUPS_MANAGE_MEMBER); return permissionByNature; }
From source file:org.shaman.terrain.vegetation.TreePlanter.java
@SuppressWarnings("unchecked") private static synchronized void INIT(AssetManager assetManager) { if (TREES != null) { return;//from w ww. j a v a 2 s.c o m } assetManager.registerLocator(ImpositorCreator.OUTPUT_FOLDER, FileLocator.class); TREES = new EnumMap<>(Biome.class); //load tree data try (ObjectInputStream in = new ObjectInputStream( new BufferedInputStream(new FileInputStream(ImpositorCreator.TREE_DATA_FILE)))) { List<TreeInfo> list = (List<TreeInfo>) in.readObject(); for (Biome b : Biome.values()) { List<Pair<Float, TreeInfo>> trees = new ArrayList<>(); float p = 0; for (TreeInfo t : list) { if (t.biome == b) { t.highResLeavesFadeFar *= TerrainHeighmapCreator.TERRAIN_SCALE; t.highResLeavesFadeNear *= TerrainHeighmapCreator.TERRAIN_SCALE; t.highResStemFadeFar *= TerrainHeighmapCreator.TERRAIN_SCALE; t.highResStemFadeNear *= TerrainHeighmapCreator.TERRAIN_SCALE; t.impostorFadeFar *= TerrainHeighmapCreator.TERRAIN_SCALE; t.impostorFadeNear *= TerrainHeighmapCreator.TERRAIN_SCALE; p += t.probability; trees.add(new ImmutablePair<>(p, t)); } } TREES.put(b, trees.toArray(new Pair[trees.size()])); } LOG.info("tree information loaded"); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(TreePlanter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.vandermeer.skb.interfaces.strategies.maps.abstractmap.EnumMapStrategy.java
@Override default EnumMap<K, V> get(Map<K, V> map) { return new EnumMap<>(map); }
From source file:com.relicum.ipsum.Configuration.RankMap.java
/** * Instantiates a new Rank map This is currently required even though all other methods are static. * Will be fixing this shortly./* ww w. j a v a 2s . c om*/ */ public RankMap() { rankMap = Collections.synchronizedMap(new EnumMap<>(GameRanks.class)); rankMap.put(GameRanks.NOOB, DARK_GRAY); rankMap.put(GameRanks.VIP, GRAY); rankMap.put(GameRanks.MVP, AQUA); rankMap.put(GameRanks.HERO, GOLD); rankMap.put(GameRanks.MOD, LIGHT_PURPLE); rankMap.put(GameRanks.ADMIN, DARK_PURPLE); rankMap.put(GameRanks.DEV, BLUE); rankMap.put(GameRanks.OWNER, RED); }
From source file:org.github.aenygmatic.payroll.usecases.postprocessors.EmployeeComponentEnumMapPostProcessor.java
@Override protected Map<EmployeeType, Object> newEnumMap() { return new EnumMap<>(EmployeeType.class); }
From source file:fr.free.movierenamer.stream.VideoDetective.java
@Override public Map<Quality, URL> getLinks(URL url) throws Exception { Map<Quality, URL> links = new EnumMap<Quality, URL>(Quality.class); String strUrl = url.toString(); String id = strUrl.substring(strUrl.lastIndexOf("/") + 1); String uri = "http://video.internetvideoarchive.net/player/6/configuration.ashx?customerid=" + id + "&publishedid=7299&reporttag=vdbetatitle&playerid=641&autolist=0&domain=www.videodetective.com&maxrate=high&minrate=low&socialplayer=false"; JSONObject json = URIRequest.getJsonDocument(new URL(uri).toURI()); String error = JSONUtils.selectString("/error", json); if (error != null && !error.equals("")) { return links; }// www .j a va2 s . c o m List<JSONObject> sources = JSONUtils.selectList("//sources", json); for (JSONObject source : sources) { String label = JSONUtils.selectString("label", source); if (label == null) { continue; } if (label.equals("2500 kbs") || label.equals("1500 kbs")) { if (links.get(Quality.HD) == null) { links.put(Quality.HD, new URL(JSONUtils.selectString("file", source))); } } else if (label.equals("750 kbs") || label.equals("450 kbs")) { if (links.get(Quality.SD) == null) { links.put(Quality.SD, new URL(JSONUtils.selectString("file", source))); } } else if (label.equals("212 kbs") || label.equals("80 kbs")) { if (links.get(Quality.SD) == null) { links.put(Quality.LD, new URL(JSONUtils.selectString("file", source))); } } } return links; }
From source file:de.vandermeer.skb.interfaces.strategies.maps.abstractmap.EnumMapStrategy.java
/** * Returns a new enum map for given key type. * @param keyType key type/*from w w w.java2 s . c o m*/ * @return new enum map */ default EnumMap<K, V> get(Class<K> keyType) { return new EnumMap<>(keyType); }
From source file:net.sf.reportengine.core.steps.TestDataRowsOutputStep.java
@Test public void testExecuteScenario1() { DataRowsOutputStep classUnderTest = new DataRowsOutputStep(); AlgoContext reportContext = new DefaultAlgorithmContext(); Map<AlgoIOKeys, Object> mockAlgoInput = new EnumMap<AlgoIOKeys, Object>(AlgoIOKeys.class); StringWriter testWriter = new StringWriter(); MockReportOutput mockOutput = new MockReportOutput(testWriter); reportContext.set(StepIOKeys.LOCAL_REPORT_INPUT, Scenario1.INPUT); //reportContext.set(ContextKeys.NEW_LOCAL_REPORT_OUTPUT, mockOutput); mockAlgoInput.put(AlgoIOKeys.DATA_COLS, Scenario1.DATA_COLUMNS); mockAlgoInput.put(AlgoIOKeys.GROUP_COLS, Scenario1.GROUPING_COLUMNS); mockAlgoInput.put(AlgoIOKeys.NEW_REPORT_OUTPUT, mockOutput); reportContext.set(StepIOKeys.DATA_ROW_COUNT, 0); classUnderTest.init(new StepInput(mockAlgoInput, reportContext)); NewRowEvent dataRowEvent = new NewRowEvent(Scenario1.ROW_OF_DATA_1); StepResult<Integer> stepResult = classUnderTest.execute(dataRowEvent, new StepInput(mockAlgoInput, reportContext)); Assert.assertNotNull(stepResult);// w w w . j a v a 2 s.co m Assert.assertEquals(NumberUtils.INTEGER_ONE, stepResult.getValue()); //(ContextKeys.DATA_ROW_COUNT)); reportContext.set(StepIOKeys.DATA_ROW_COUNT, stepResult.getValue()); dataRowEvent = new NewRowEvent(Scenario1.ROW_OF_DATA_2); stepResult = classUnderTest.execute(dataRowEvent, new StepInput(mockAlgoInput, reportContext)); Assert.assertNotNull(stepResult); Assert.assertEquals(Integer.valueOf(2), stepResult.getValue()); reportContext.set(StepIOKeys.DATA_ROW_COUNT, stepResult.getValue()); dataRowEvent = new NewRowEvent(Scenario1.ROW_OF_DATA_3); stepResult = classUnderTest.execute(dataRowEvent, new StepInput(mockAlgoInput, reportContext)); Assert.assertNotNull(stepResult); Assert.assertEquals(Integer.valueOf(3), stepResult.getValue()); reportContext.set(StepIOKeys.DATA_ROW_COUNT, stepResult.getValue()); dataRowEvent = new NewRowEvent(Scenario1.ROW_OF_DATA_4); stepResult = classUnderTest.execute(dataRowEvent, new StepInput(mockAlgoInput, reportContext)); Assert.assertNotNull(stepResult); Assert.assertEquals(Integer.valueOf(4), stepResult.getValue()); reportContext.set(StepIOKeys.DATA_ROW_COUNT, stepResult.getValue()); dataRowEvent = new NewRowEvent(Scenario1.ROW_OF_DATA_5); stepResult = classUnderTest.execute(dataRowEvent, new StepInput(mockAlgoInput, reportContext)); Assert.assertNotNull(stepResult); Assert.assertEquals(Integer.valueOf(5), stepResult.getValue()); reportContext.set(StepIOKeys.DATA_ROW_COUNT, stepResult.getValue()); dataRowEvent = new NewRowEvent(Scenario1.ROW_OF_DATA_6); stepResult = classUnderTest.execute(dataRowEvent, new StepInput(mockAlgoInput, reportContext)); Assert.assertNotNull(stepResult); Assert.assertEquals(Integer.valueOf(6), stepResult.getValue()); reportContext.set(StepIOKeys.DATA_ROW_COUNT, stepResult.getValue()); //CellProps[][] resultCellMatrix = Scenario1.OUTPUT.getDataCellMatrix(); //Assert.assertTrue(MatrixUtils.compareMatrices(Scenario1.EXPECTED_OUTPUT_DATA, resultCellMatrix)); System.out.println(testWriter.getBuffer()); }