Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

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

Prototype

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

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:dynamicrefactoring.domain.xml.ExportImportUtilities.java

/**
 * Se encarga del proceso de exportacin de un plan de refactorizaciones
 * dinmicas./* w  ww.j  a  v a  2s.c om*/
 * 
 * @param destination
 *            directorio a donde se quiere exportar el plan.
 * @throws IOException
 *             IOException.
 * @throws XMLRefactoringReaderException
 *             XMLRefactoringReaderException.
 */
public static void exportRefactoringPlan(String destination) throws IOException, XMLRefactoringReaderException {
    if (new File(destination + "/refactoringPlan").exists()) { //$NON-NLS-1$
        FileManager.emptyDirectories(destination + "/refactoringPlan"); //$NON-NLS-1$
        FileManager.deleteDirectories(destination + "/refactoringPlan", true); //$NON-NLS-1$
    }
    // Creamos el directorio donde se guardar el plan.
    FileUtils.forceMkdir(new File(destination + "/refactoringPlan")); //$NON-NLS-1$
    // Copiamos el fichero xml que guarda la informacin relativa al plan.

    FileManager.copyFile(new File(RefactoringConstants.REFACTORING_PLAN_FILE),
            new File(destination + "/refactoringPlan/" //$NON-NLS-1$
                    + new File(RefactoringConstants.REFACTORING_PLAN_FILE).getName()));
    FileManager.copyFile(new File(RefactoringConstants.REFACTORING_PLAN_DTD),
            new File(destination + "/refactoringPlan/" //$NON-NLS-1$
                    + new File(RefactoringConstants.REFACTORING_PLAN_DTD).getName()));

    // Creamos una carpeta donde guardaremos las refactorizaciones.
    String refactoringDestination = destination + "/refactoringPlan/refactorings"; //$NON-NLS-1$

    FileUtils.forceMkdir(new File(refactoringDestination));

    // Pasamos a exportar las refactorizaciones necesarias dentro de la
    // carpeta anterior.
    ArrayList<String> refactorings = RefactoringPlanReader.readAllRefactoringsFromThePlan();
    HashMap<String, String> allRefactorings = DynamicRefactoringLister.getInstance()
            .getDynamicRefactoringNameList(RefactoringPlugin.getDynamicRefactoringsDir(), true, null);

    allRefactorings.putAll(DynamicRefactoringLister.getInstance().getDynamicRefactoringNameList(
            RefactoringPlugin.getNonEditableDynamicRefactoringsDir(), true, null));

    for (String next : refactorings) {
        String key = next + " (" + next + ".xml)"; //$NON-NLS-1$ //$NON-NLS-2$
        String definition = allRefactorings.get(key);// ruta del fichero de
        // definicin de al
        // refactorizacin
        exportRefactoring(refactoringDestination, definition, true);
    }
}

From source file:net.spfbl.whois.AutonomousSystem.java

public static synchronized HashMap<String, AutonomousSystem> getMap() {
    HashMap<String, AutonomousSystem> map = new HashMap<String, AutonomousSystem>();
    map.putAll(MAP);
    return map;//ww w . j a  va  2 s  . c o  m
}

From source file:org.epics.archiverappliance.utils.ui.GetUrlContent.java

@SuppressWarnings("unchecked")
public static void combineJSONObjectsWithArrays(HashMap<String, Object> dest, JSONObject additionalDetails) {
    if (additionalDetails != null)
        dest.putAll(additionalDetails);
}

From source file:org.epics.archiverappliance.utils.ui.GetUrlContent.java

/**
 * A static utilty method to combine JSON objects
 * @param dest Details from additionalDetails are added to this. 
 * @param additionalDetails JSONObject//from w  ww .j a  v a 2 s . com
 */
@SuppressWarnings("unchecked")
public static void combineJSONObjects(HashMap<String, String> dest, JSONObject additionalDetails) {
    if (additionalDetails != null)
        dest.putAll(additionalDetails);
}

From source file:net.spfbl.whois.Owner.java

public static synchronized HashMap<String, Owner> getMap() {
    HashMap<String, Owner> map = new HashMap<String, Owner>();
    map.putAll(MAP);
    return map;// w  w  w.j av a 2  s.  co  m
}

From source file:info.varden.anatychia.Main.java

public static MaterialDataList materialList(SaveData save, ProgressUpdater pu, MaterialData[] filters) {
    Random random = new Random();
    boolean filtersNull = filters == null;
    pu.updated(0, 1);//from   www .j  a v a 2s . c  om
    pu.updated(-3, 1);
    MaterialDataList mdl = new MaterialDataList();
    File saveDir = save.getLocation();
    File[] regionFolders = listRegionContainers(saveDir);
    int depth = Integer.MAX_VALUE;
    File shallowest = null;
    for (File f : regionFolders) {
        String path = f.getAbsolutePath();
        Pattern p = Pattern.compile(Pattern.quote(File.separator));
        Matcher m = p.matcher(path);
        int count = 0;
        while (m.find()) {
            count++;
        }
        if (count < depth) {
            depth = count;
            if (shallowest == null || f.getName().equalsIgnoreCase("region")) {
                shallowest = f;
            }
        }
    }
    pu.updated(-1, 1);
    ArrayList<File> regions = new ArrayList<File>();
    int tfs = 0;
    for (File f : regionFolders) {
        String dimName = f.getParentFile().getName();
        boolean deleted = false;
        if (f.equals(shallowest)) {
            dimName = "DIM0";
        }
        if (!filtersNull) {
            for (MaterialData type : filters) {
                if (type.getType() == MaterialType.DIMENSION && type.getName().equals(dimName)) {
                    System.out.println("Deleting: " + dimName);
                    deleted = recursiveDelete(f);
                }
            }
        }
        if (deleted)
            continue;
        mdl.increment(new MaterialData(MaterialType.DIMENSION, dimName, 1L));
        File[] r = f.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".mca");
            }

        });
        int max = r.length;
        int cur = 0;
        for (File valid : r) {
            cur++;
            try {
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(valid));
                byte[] offsetHeader = new byte[4096];
                bis.read(offsetHeader, 0, 4096);
                bis.close();
                ByteBuffer bb = ByteBuffer.wrap(offsetHeader);
                IntBuffer ib = bb.asIntBuffer();
                while (ib.remaining() > 0) {
                    if (ib.get() != 0) {
                        tfs++;
                    }
                }
                bb = null;
                ib = null;
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
            // tfs += Math.floor(valid.length() / 1000D);
            pu.updated(cur, max);
        }
        regions.addAll(Arrays.asList(r));
    }
    if (regions.size() <= 0) {
        pu.updated(1, 1);
        return mdl;
    }
    pu.updated(-2, 1);
    int fc = 0;
    int fs = 0;
    for (File region : regions) {
        fc++;
        //fs += Math.floor(region.length() / 1000D);
        try {
            RegionFile anvil = new RegionFile(region);
            for (int x = 0; x < 32; x++) {
                for (int z = 0; z < 32; z++) {
                    InputStream is = anvil.getChunkDataInputStream(x, z);
                    if (is == null)
                        continue;
                    NBTInputStream nbti = new NBTInputStream(is, CompressionMode.NONE);
                    CompoundTag root = (CompoundTag) nbti.readTag();
                    String rootName = root.getName();
                    CompoundTag level = (CompoundTag) root.getValue().get("Level");
                    Map<String, Tag> levelTags = level.getValue();
                    ListTag sectionTag = (ListTag) levelTags.get("Sections");
                    ArrayList<Tag> sections = new ArrayList<Tag>(sectionTag.getValue());
                    for (int i = 0; i < sections.size(); i++) {
                        mdl.setSectorsRelative(1);
                        CompoundTag sect = (CompoundTag) sections.get(i);
                        Map<String, Tag> sectTags = sect.getValue();
                        ByteArrayTag blockArray = (ByteArrayTag) sectTags.get("Blocks");
                        byte[] add = new byte[0];
                        boolean hasAdd = false;
                        if (sectTags.containsKey("Add")) {
                            hasAdd = true;
                            ByteArrayTag addArray = (ByteArrayTag) sectTags.get("Add");
                            add = addArray.getValue();
                        }
                        byte[] blocks = blockArray.getValue();
                        for (int j = 0; j < blocks.length; j++) {
                            short id;
                            byte aid = (byte) 0;
                            if (hasAdd) {
                                aid = ChunkFormat.Nibble4(add, j);
                                id = (short) ((blocks[j] & 0xFF) + (aid << 8));
                            } else {
                                id = (short) (blocks[j] & 0xFF);
                            }
                            if (!filtersNull) {
                                for (MaterialData type : filters) {
                                    if (type.getType() == MaterialType.BLOCK
                                            && type.getName().equals(String.valueOf(blocks[j] & 0xFF))
                                            && (type.getRemovalChance() == 1D
                                                    || random.nextDouble() < type.getRemovalChance())) {
                                        blocks[j] = (byte) 0;
                                        if (aid != 0) {
                                            add[j / 2] = (byte) (add[j / 2] & (j % 2 == 0 ? 0xF0 : 0x0F));
                                        }
                                        id = (short) 0;
                                    }
                                }
                            }
                            mdl.increment(new MaterialData(MaterialType.BLOCK, String.valueOf(id), 1L));
                        }
                        if (!filtersNull) {
                            HashMap<String, Tag> rSectTags = new HashMap<String, Tag>();
                            rSectTags.putAll(sectTags);
                            ByteArrayTag bat = new ByteArrayTag("Blocks", blocks);
                            rSectTags.put("Blocks", bat);
                            if (hasAdd) {
                                ByteArrayTag adt = new ByteArrayTag("Add", add);
                                rSectTags.put("Add", adt);
                            }
                            CompoundTag rSect = new CompoundTag(sect.getName(), rSectTags);
                            sections.set(i, rSect);
                        }
                    }
                    ListTag entitiesTag = (ListTag) levelTags.get("Entities");
                    ArrayList<Tag> entities = new ArrayList<Tag>(entitiesTag.getValue());
                    for (int i = entities.size() - 1; i >= 0; i--) {
                        CompoundTag entity = (CompoundTag) entities.get(i);
                        Map<String, Tag> entityTags = entity.getValue();
                        if (entityTags.containsKey("id")) {
                            StringTag idTag = (StringTag) entityTags.get("id");
                            String id = idTag.getValue();
                            boolean removed = false;
                            if (!filtersNull) {
                                for (MaterialData type : filters) {
                                    if (type.getType() == MaterialType.ENTITY
                                            && (type.getName().equals(id) || type.getName().equals(""))
                                            && (type.getRemovalChance() == 1D
                                                    || random.nextDouble() < type.getRemovalChance())) {
                                        if (type.fulfillsRequirements(entity)) {
                                            entities.remove(i);
                                            removed = true;
                                        }
                                    }
                                }
                            }
                            if (!removed) {
                                mdl.increment(new MaterialData(MaterialType.ENTITY, id, 1L));
                            }
                        }
                    }
                    nbti.close();
                    is.close();
                    if (!filtersNull) {
                        HashMap<String, Tag> rLevelTags = new HashMap<String, Tag>();
                        rLevelTags.putAll(levelTags);
                        ListTag rSectionTag = new ListTag("Sections", CompoundTag.class, sections);
                        rLevelTags.put("Sections", rSectionTag);
                        ListTag rEntityTag = new ListTag("Entities", CompoundTag.class, entities);
                        rLevelTags.put("Entities", rEntityTag);
                        final CompoundTag rLevel = new CompoundTag("Level", rLevelTags);
                        HashMap<String, Tag> rRootTags = new HashMap<String, Tag>() {
                            {
                                put("Level", rLevel);
                            }
                        };
                        CompoundTag rRoot = new CompoundTag(rootName, rRootTags);
                        OutputStream os = anvil.getChunkDataOutputStream(x, z);
                        NBTOutputStream nbto = new NBTOutputStream(os, CompressionMode.NONE);
                        nbto.writeTag(rRoot);
                        nbto.close();
                    }
                    fs++;
                    pu.updated(fs, tfs);
                }
            }
            anvil.close();
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    MaterialData[] data = mdl.toArray();
    System.out.println("FILES SCANNED: " + fc);
    for (MaterialData d : data) {
        System.out.println(d.getType().getName() + ": " + d.getName() + " (" + d.getQuantity() + ")");
    }
    return mdl;
}

From source file:org.jbpm.designer.server.diagram.DiagramBuilder.java

/**
 * Prepare a model JSON for analyze, resolves the hierarchical structure
 * creates a HashMap which contains all resourceIds as keys and for each key
 * the JSONObject, all id are keys of this map
 * /*from   www. j ava 2  s. c o  m*/
 * @param object
 * @return a HashMap keys: all ressourceIds values: all child JSONObjects
 * @throws org.json.JSONException
 */
public static HashMap<String, JSONObject> flatRessources(JSONObject object) throws JSONException {
    HashMap<String, JSONObject> result = new HashMap<String, JSONObject>();

    // no cycle in hierarchies!!
    if (object.has("resourceId") && object.has("childShapes")) {
        result.put(object.getString("resourceId"), object);
        JSONArray childShapes = object.getJSONArray("childShapes");
        for (int i = 0; i < childShapes.length(); i++) {
            result.putAll(flatRessources(childShapes.getJSONObject(i)));
        }

    }
    ;

    return result;
}

From source file:net.spfbl.dnsbl.QueryDNSBL.java

public static HashMap<String, ServerDNSBL> getMap() {
    HashMap<String, ServerDNSBL> map = new HashMap<String, ServerDNSBL>();
    map.putAll(MAP);
    return map;//from   w w  w.  j ava  2  s . com
}

From source file:com.fujitsu.dc.test.utils.CellUtils.java

/**
 * ImplicitFlow??./*from  www . j a va2 s.  c o m*/
 * @param cellName Cell??
 * @param schemaCell ?Cell??
 * @param schemaAccount ?Cell???
 * @param schemaPassword ?Cell???
 * @param redirectPath ?
 * @param state ???????????
 * @param addHeader ?
 * @return ?
 * @throws DcException 
 */
public static DcResponse implicitflowAuthenticate(String cellName, String schemaCell, String schemaAccount,
        String schemaPassword, String redirectPath, String state, HashMap<String, String> addHeader)
        throws DcException {
    String clientId = UrlUtils.cellRoot(schemaCell);
    if (null == redirectPath) {
        redirectPath = "__/redirect.html";
    }

    String body = "response_type=token&client_id=" + clientId + "&redirect_uri=" + clientId + redirectPath
            + "&username=" + schemaAccount + "&password=" + schemaPassword + "&state=" + state;

    DcRestAdapter rest = new DcRestAdapter();

    // 
    HashMap<String, String> requestheaders = new HashMap<String, String>();
    if (addHeader != null) {
        requestheaders.putAll(addHeader);
    }
    requestheaders.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);

    return rest.post(UrlUtils.cellRoot(cellName) + "__authz", body, requestheaders);
}

From source file:io.personium.test.utils.CellUtils.java

/**
 * ImplicitFlow??.//ww  w. ja  va2  s  .  c  o m
 * @param cellName Cell??
 * @param schemaCell ?Cell??
 * @param schemaAccount ?Cell???
 * @param schemaPassword ?Cell???
 * @param redirectPath ?
 * @param state ???????????
 * @param addHeader ?
 * @return ?
 * @throws PersoniumException 
 */
public static PersoniumResponse implicitflowAuthenticate(String cellName, String schemaCell,
        String schemaAccount, String schemaPassword, String redirectPath, String state,
        HashMap<String, String> addHeader) throws PersoniumException {
    String clientId = UrlUtils.cellRoot(schemaCell);
    if (null == redirectPath) {
        redirectPath = "__/redirect.html";
    }

    String body = "response_type=token&client_id=" + clientId + "&redirect_uri=" + clientId + redirectPath
            + "&username=" + schemaAccount + "&password=" + schemaPassword + "&state=" + state;

    PersoniumRestAdapter rest = new PersoniumRestAdapter();

    // 
    HashMap<String, String> requestheaders = new HashMap<String, String>();
    if (addHeader != null) {
        requestheaders.putAll(addHeader);
    }
    requestheaders.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);

    return rest.post(UrlUtils.cellRoot(cellName) + "__authz", body, requestheaders);
}